Hello I am having a bit of trouble with my php code. I have a Moodle site and I am able to grab user information. What I am trying to do:
- My Steps of madness
- Grab first and last name of user (Variables are correct and work)
- I am generating a Random seed using MD5 HASH and setting as the cookie
- Then I take users "userid" and combine it with the MD5 seed to concatenate them together.
- I set the newly generated MD5 HAS cookie to expire in 30 seconds
- I verify cookie conditions (if user is not logged in the userid is 0)
- If all conditions are met they will be directed to the $locations variable address using header redirect.
- If conditions are not met they are redirect to a 404 page.
I am always getting the 404. Thank You in advance for any help.
<?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");
?>