如何读取以下url:
localhost/index.php?errormsg=错误密码
所以我希望它将变量$errormsg设置为"错误密码",我该怎么做?我确信有一种方法可以使用$_GET或$_POST?
您想要使用$_GET['errormsg']
。
应该这样做:
if isset($_GET['errormsg'])
{
echo $_GET['errormsg'];
}
$errormsg = $_GET['errormsg']
这应该会为您带来
$_GET['errormsg']
是您问题的答案。
print_r($_GET)
以查看URL中的所有变量。在这种情况下,您需要
$_GET['errormsg']
你和以前一样亲密。一个谷歌就会给你答案:)
http://php.net/manual/en/reserved.variables.get.php
<?php
// use htmlspecialchars() to clean up url-encoded characters
$error_message = htmlspecialchars($_GET["errormsg"]);
echo 'Error: ' . $error_message;
?>
prints: "Error: error_here"
,如果url=...?errormsg=error_here