[英]PHP redirect with conditions
Hello I am having a bit of trouble with my php code. 您好,我的php代码有点麻烦。 I have a Moodle site and I am able to grab user information.
我有一个Moodle网站,可以获取用户信息。 What I am trying to do:
我正在尝试做的是:
I am always getting the 404. Thank You in advance for any help. 我总是收到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");
?>
Your if statement will always evaluate to false because this section always evaluates to False. 您的if语句将始终评估为false,因为此部分始终将评估为False。
$randomcookie."_".$userid !== $randomcookie."_".$userid
Are you trying to set the cookie on this page, then verify if the cookie on the page you are redirecting to, or are you trying to both set the cookie, and verify the cookie/login on this page? 您是要在此页面上设置cookie,然后验证是否要重定向到该页面上的cookie,还是要同时设置cookie并验证此页面上的cookie /登录名?
我相信解决以下部分将解决问题。
$randomcookie."_".$userid !== $randomcookie."_".$userid
关于什么 ?
setcookie("MoodleSession", $random, time()+ 30, '/',"", 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.