我的代码在localhost上完美运行。但是,当我上传网页时,无论选择何种选项,它都会显示会话结束时间,就像浏览器会话结束时一样。这是第一页的代码
<pre><code>
session_start();
error_reporting(0);
if(isset($_SESSION['over18'])){
header("location: index.php");
}
if(isset($_SESSION['under18'])){
header("location: leave.php");
}
if(isset($_POST['submit'])){
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$remember = $_POST['remember'];
$birthday = mktime(0,0,0,$month,$day, $year);
$difference = time()-$birthday;
$age = floor($difference/31556926);
if($age >= 18){
$_SESSION['over18']=1;
switch ($remember) {
case 1:
header("location: index.php?sessionid=1");
break;
case 2:
header("location: index.php?sessionid=2");
break;
case 3:
header("location: index.php?sessionid=3");
break;
case 4:
header("location: index.php?sessionid=4");
break;
case 5:
header("location: index.php?sessionid=5");
break;
case 6:
header("location: index.php?sessionid=6");
break;
default:
header("location: index.php?sessionid=1");
break;
}
} else {
$_SESSION['under18']=0;
header("location: leave.php");
}
}<!-- language: lang-none -->
p class="pos_fixed3">Remember me for: select name="remember">
option value="1">This Session Only</option>
option value="2">1 Hour</option>
option value="3">5 Hours</option>
option value="4">1 Day</option>
option value="5">1 Week</option>
option value="6">1 Month</option> </p>
</select>
</pre></code>
我的index.php代码低于
if(isset($_GET["sessionid"])){
$session = $_GET["sessionid"];
} else {
$session = "";
}
switch ($session) {
case '1':
session_set_cookie_params();
break;
case '2':
session_set_cookie_params('3600');
break;
case '3':
session_set_cookie_params('18000');
break;
case '4':
session_set_cookie_params('86400');
break;
case '5':
session_set_cookie_params('604800');
break;
case '6':
session_set_cookie_params('18144000');
break;
default:
session_set_cookie_params('');
break;
}
session_start();
if(!$_SESSION['over18']){
header("location: age.php");
}
答案 0 :(得分:0)
IN index.php。 开始会话开始pgae
session_start();
if(!$_SESSION['over18']){
header("location: age.php");
}
在你的代码之后。
if(isset($_GET["sessionid"])){
$session = $_GET["sessionid"];
} else {
$session = "";
}
switch ($session) {
case '1':
session_set_cookie_params();
break;
case '2':
session_set_cookie_params('3600');
break;
case '3':
session_set_cookie_params('18000');
break;
case '4':
session_set_cookie_params('86400');
break;
case '5':
session_set_cookie_params('604800');
break;
case '6':
session_set_cookie_params('18144000');
break;
default:
session_set_cookie_params('');
break;
}
希望这会奏效。