【发布时间】:2019-03-02 07:07:19
【问题描述】:
您好,我的 php 代码有点问题。 我有一个 Moodle 网站,我可以获取用户信息。 我正在尝试做的事情:
- 我的疯狂之路
- 获取用户的名字和姓氏(变量正确且有效)
- 我正在使用 MD5 HASH 生成随机种子并设置为 cookie
- 然后我将用户“userid”与 MD5 种子结合起来,将它们连接在一起。
- 我将新生成的 MD5 HAS cookie 设置为 30 秒后过期
- 我验证 cookie 条件(如果用户未登录用户 ID 为 0)
- 如果满足所有条件,它们将使用标头重定向定向到 $locations 变量地址。
- 如果不满足条件,它们将被重定向到 404 页面。
我总是收到 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");
?>
【问题讨论】:
标签: php redirect cookies verification