我正在制作一个激活页面,在用户注册到网站后会被邮寄给用户,但我的代码中有错误:
Undefined index: ActivationKey
用户将获得的链接将是
website-url/activate.php?Username=user&ActivationKey=foobar
它给出了这行代码的错误:
$ActivationKey = $_SESSION['ActivationKey'];
我的代码如下:
<?PHP
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect("127.0.0.1","root","XXX");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("monitron");
if(!$db) {
die("Unable to select database");
}
//Start session
session_start();
//check if Username is already in session and
//use it if it is
//else, grab it from GET
//use it from GET
if(!empty($_SESSION['Username'])){
$Username = $_SESSION['Username'];
}else if(isset($_GET['Username'])){
$_SESSION['Username'] = $_GET['Username'];
$Username = $_SESSION['Username'];
};
//Grab activationkey from session.
if(isset($_GET['ActivationKey'])){
$_SESSION['ActivationKey'] = $_GET['ActivationKey'];
};
$ActivationKey = $_SESSION['ActivationKey'];
echo $ActivationKey;
echo $Username;
//Create update query to update activation status
$qry = "UPDATE login SET ActivationStatus = 'Active' WHERE Username = '$Username'";
$result = @mysql_query($qry)
?>
如果有人可以帮我解决这个问题,我会很感激:)
答案 0 :(得分:1)
你有行
if(isset($_GET['ActivationKey'])){
$_SESSION['ActivationKey'] = $_GET['ActivationKey'];
};
$ActivationKey = $_SESSION['ActivationKey'];
但是,如果if语句永远不成立,那么没有$ _SESSION ['ActivationKey'],那就是PHP抱怨的错误。