为了提高我的网址并简化多步激活过程,我已将我的网页编程为将激活电子邮件中的用户ID和激活码存储为会话变量。当userID和actCode在url中时,它会将它们保存为会话变量,然后重定向到激活(我已经使用htaccess来取消.php部分)
它第一次工作(当页面刷新时),但当你移动到另一个步骤或手动刷新页面时,它会擦除它们。
这是我的代码:
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
if ( (!empty($_GET['u'])) && (!empty($_GET['a'])) ) {
$_SESSION["activate_userID"] = $_GET['u'];
$_SESSION["activate_actCode"] = $_GET['a'];
header( 'Location:activate') ;
}else{
$userID = $_SESSION["activate_userID"];
$actCode = $_SESSION["activate_actCode"];
echo 'session variable found: '.$actCode;
}
if ($actCode == ""){$actCode = "nUlL";}
require "***connection script***";
$checkCode = "SELECT ***account details***, `activationExpire` FROM `users` WHERE `userID` = \"$userID\"; ";
$result = $conn->query($checkCode);
if ($result->num_rows > 0) {
// output data of each row
while($actInfo = $result->fetch_assoc()) {
*** account details are here ***
$step = $actInfo['activationStatus'];
$activationCode = $actInfo['activationCode'];
$activationExpire = $actInfo['activationExpire'];
}
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Activate - FiestaUSA</title>
<link href="includes/css/materialize.min.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="blue" background="includes/images/bg.jpg" style="background-size: cover;">
<div class="row">
<div class="col s10 m8 l6 offset-s1 offset-m2 offset-l3" style="padding-top: 50px">
<div class="card-panel z-depth-2 ">
<div class="row center">
<img src="includes/images/white480.png">
</div>
<div class="row">
<?php
$now = date('Y-m-d H:i:s');
if($actCode !== $activationCode) {
echo '
<p>
There was a problem activating your account. Please email
<a href="mailto:activation@fiestausa.com?Subject=Account%20Activation">activation@fiestausa.com</a>
</p>
';
}
elseif ($activationExpire < $now){
echo '
<p>
Your activation code has expired. Please email
<a href="mailto:activation@fiestausa.com?Subject=Account%20Activation">activation@fiestausa.com</a>
</p>
';
;} else {
if ($step == 6){
header( 'Location:signin') ;
}
if ($step == 5){
require "includes/php/activation/s5.php";
}
if ($step == 4){
require "includes/php/activation/s4.php";
}
elseif ($step == 3){
require "includes/php/activation/s3.php";
}
elseif ($step == 2){
require "includes/php/activation/s2.php";
}
elseif ($step == 1){
require "includes/php/activation/s1.php";
}
}
?>
</div>
</div>
</div>
</div>
</body>
</html>
您可以在以下位置进行测试 http://fiestausa.com/myevent/activate.php?u=2&a=fiverr
答案 0 :(得分:0)
您的会话可能返回意外行为的原因。你提到了你要发的redirect
。但是,您是否重定向到同一个域和子域?
如果您的网站同时查询www和非www版本,那么您可能会获得不同的会话,因为它们被视为不同的子域。您可以更改您的htaccess来解决此问题,或者您可以通过进入开发控制台并键入document.cookie并比较这两个页面来进行检查。