我使用的是PHP 5.4.6和MySQL 5.5.27以及Apache 2.4.2。
我的问题是,我试图使用$_GET
获取URL传递变量的值,但总是会出现一个错误,在此行中显示:Undefined index:err in thispage.php。
我环顾四周,发现大多数开发人员都通过使用isset()
函数解决了这个问题。但这并不能解决我的问题,因为我需要获得URL中发送的变量的实际值!
URL为http://localhost/Edugate/index.php?err=1
。
这是我在index.php
页面中的代码:
<?php
$error = $_GET['err'];
if($error == 1)
print "<img src='icons/error.png' alt='error'> Icorrect usename or password...";
?>
您可以使用像这样简单的东西
$error = isset($_GET['err']) ? (int)$_GET['err'] : null;
if ($error !== null) {
// error
}
// or
if ($error === 1) {
} else if ($error === 2) {
}
按照其他开发人员的规定使用isset
。
<?php
if(isset($_GET['err']) && $_GET['err'] == 1)
print "<img src='icons/error.png' alt='error'> Incorrect username or password...";
?>
*顺便说一句,*用户名不正确。