php 页面跳转方式总结
php传值有两种:$_GET 和 $_POST
先说GET:
<form action="welcome.php" method="get"> Name: <input name="name" type="text" /> Age: <input name="age" type="text" /> <input type="submit" /> </form>
表单,用get方法传值给welcome.php
点击发送时,url会以这种形式表示:http://×××× /welcome.php?name=××××&age=××
welcome.php通过$_GET[] 来取得值:
Welcome <?php echo $_GET["name"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old!
使用$_GET 变量时,参数会显示在url中,而且参数不能大于100个字符
但$_GET 可以保存书签,下次直接打开
再说$_POST变量:
<form action="welcome.php" method="post"> Enter your name: <input type="text" name="name" /> Enter your age: <input type="text" name="age" /> <input type="submit" /> </form>
表单通过$_POST 变量传值
$_POST 不会把参数显示在url中,而且长度也没有限制
获取$_POST 变量:
Welcome <?php echo $_POST["name"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old!
$_REQUEST 变量
PHP 的 $_REQUEST 变量包含了 $_GET, $_POST 以及 $_COOKIE 的内容。
PHP 的 $_REQUEST 变量可用来取得通过 GET 和 POST 方法发送的表单数据的结果。
Welcome <?php echo $_REQUEST["name"]; ?>.<br /> You are <?php echo $_REQUEST["age"]; ?> years old!
如非注明 均属原创 如需转载 都请注明: Alien的博客
浙公网安备 33010602011771号