I am setting up an admin panel for a website, and everything was working fine on my local (MAMP) server. I uploaded the website to the server and the user authentication isn't working anymore. I am able to get a success from the server, but when I'm entering into a page, PHP can't find the required session variable, and thus redirects the user back to the sign in page.
I have tried on both PHP version 5 and 7. I have tried echoing the session variable upon verification. I have tried to simply store the variable on one page and reading it on another page in the same folder, and it didn't work as well.
page1.php
<?php
session_start();
$_SESSION["userid"] = 1;
?>
<a href="page2.php">To Page2</a>
page2.php
<?php
session_start();
if (!isset($_SESSION["userid"])) {
header("Location: page1.php");
die();
}
echo $_SESSION["userid"];
After I click the link in page1.php, page2.php redirects me to page1.php again without any error.