Hi. I’m learning to program PHP more as a hobby than anything. I’ve just joined SitePoint and this is my first (but I’m sure not last) request for assistance. And thanks in advance for any assistance.
I am working on a web site where I want a page limited to authorized individuals. When someone accesses the page (index.php file), if they have not signed in they are redirected to a login form. This redirect is working fine.
After entering their username and password, the form should redirect them back to the index.php. This works on my local server but on the live server, the login form seems to just reload but doesn’t even re-display the form. Just a blank page.
On the index.php page, I have the following:
// If an authorized user is accessing, get their access authorization level and name
if($loginAuthorized){
$accessLevel=$_COOKIE['accessLevel'];
$fullname=$_COOKIE['fullname'];
echo 'Name is: '.$fullname.'<br />';
}else{
header("Location: _forms/loginform.php");
}
As I mentioned, that works and sends the user to the login form. On the login form I have the following:
//Check whether password retreived matches one input
if ($password==$pwordRetrieved){
//success
$fullname=$fnameRetrieved.' '.$lnameRetrieved;
setcookie("loginAuthorized", "loginAuthorized", 0,"/");
setcookie("accessLevel", $accessLevelRetrieved, 0,"/");
setcookie("fullname", $fullname,0,"/");
header("Location: ../index.php");
exit();
}else{
//Not success
echo 'Incorrect user name and/or password<br />';
echo '<a href='.$thisScriptName.'>Try again</a>';
exit;
}
This one doesn’t work. As I mentioned, both redirects work fine on my local server.
If it is relevant, my local server is running PHP version 7.4.2. The hosting company for the live server is running PHP version 5.3.29.
Any ideas?