实例-get.php
<?php // 获取通过url发送的变量参数 // 键名=>变量名, 值=>变量值 function _get($str){ $val = !empty($_GET[$str]) ? $_GET[$str] : null; return $val; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>get</title> </head> <body> <form action="" method="get"> <label for="email">邮箱:</label> <input type="email" id="email" name="email" value="<?=_get('email')?:''?>"> <label for="password">密码:</label> <input type="password" id="password" name="password" value="<?=_get('password')?:''?>"> <button>登录</button> </form> </body> </html> <?php // 获取通过请求头发送的变量参数 // 键名=>变量名, 值=>变量值 echo '<pre>'; print_r($_GET); ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php // 获取通过请求头发送的变量参数 // 键名=>变量名, 值=>变量值 function _post($str){ $val = !empty($_POST[$str]) ? $_POST[$str] : null; return $val; } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>get</title> </head> <body> <form action="" method="post"> <label for="email">邮箱:</label> <input type="email" id="email" name="email" value="<?=_post('email')?:''?>"> <label for="password">密码:</label> <input type="password" id="password" name="password" value="<?=_post('password')?:''?>"> <button>登录</button> </form> </body> </html> <?php echo '<pre>'; print_r($_POST); ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例