<?php
if ($_POST) {
if ($_POST['hash'] == $_SESSION['hash']) {
echo 'Form sent!';
} else {
echo 'Error: form was already sent!';
}
}
$hash = md5(microtime());
$_SESSION['hash'] = $hash;
?>
<form method="post" action="">
<input type="hidden" name="hash" value="<?php echo $hash ?>">
<input type="text" name="test">
<input type="submit" value="submit">
</form>
Tag: php
Xdebug configurations for Xdebug2 and Xdebug3 under Windows and Linux
In your xdebug.ini file:
; For Xdebug 2 (2.5.5) / Linux
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9003
xdebug.remote_host=172.17.0.1
; For Xdebug 2 (2.5.5) / Windows
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9003
xdebug.remote_host=172.17.0.1
; For Xdebug 3 (3.1.1) / Linux
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so
xdebug.mode=debug
xdebug.discover_client_host=no
xdebug.client_port=9003
xdebug.client_host=172.17.0.1
; For Xdebug 3 (3.1.1) / Windows
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so
xdebug.mode=debug
xdebug.discover_client_host=no
xdebug.client_port=9003
xdebug.client_host=host.docker.internal
Colors in PHP CLI
Test in console:
php -r 'echo "\033[31mTEST\0330m'
Test in php file:
echo "\033[32mTEST\033[0m" . PHP_EOL;
Remember to use quotation mark instead of apostrophe.
You can set foreground and background colors.
Color codes:
FG code | BG code | Color |
30 | 40 | Black |
31 | 41 | Red |
32 | 42 | Green |
33 | 43 | Yellow |
34 | 44 | Blue |
35 | 45 | Magenta |
36 | 46 | Cyan |
37 | 47 | White |
90 | 100 | Bright Black (Gray) |
91 | 101 | Bright Red |
92 | 102 | Bright Green |
93 | 103 | Bright Yellow |
94 | 104 | Bright Blue |
95 | 105 | Bright Magenta |
96 | 106 | Bright Cyan |
97 | 107 | Bright White |