你好,我的php代码有点麻烦。 我有一个Moodle网站,可以获取用户信息。 我正在尝试做的事情:
我总是收到404。在此先感谢您的帮助。
<?php
require('../../config.php');
global $USER;
/* Session Variables */
$userid = $USER->id;
$firstname=$USER->firstname;
$lastname=$USER->lastname;
/* Random MD5 seed to set as cookie */
$random = md5(rand(1,1000));
setcookie(MoodleSession, $random, time()+ 30, '/',"", 1);
$_COOKIE['MoodleSession'] = $random;
$randomcookie = $random;
/* Where I want to go if all conditions are true */
$location="Location: https://MyDomainHere.com/uid=".$firstname."_".$lastname;
/* Response Data and verification of MD5 with firstname and lastname */
if ($randomcookie."_".$userid !== $randomcookie."_".$userid && $firstname."_".$lastname != ""){
header($location); /* Redirect browser */
die();}
/* If condition are not met, user gets a 404 */
header("Location: https://MyDomainHere.com/404");
?>
答案 0 :(得分:0)
您的if语句将始终为false,因为此部分始终为False。
$randomcookie."_".$userid !== $randomcookie."_".$userid
您是要在此页面上设置cookie,然后验证是否要重定向到该页面上的cookie,还是要同时设置cookie并验证此页面上的cookie /登录?
答案 1 :(得分:0)
我相信修正以下部分将解决问题。
$randomcookie."_".$userid !== $randomcookie."_".$userid
答案 2 :(得分:0)
那又如何呢?
setcookie("MoodleSession", $random, time()+ 30, '/',"", 1);