I have a login script coded in php and mysqli. upon submission and successful authentication it redirects to success.php to write sessions. my success page looks like this.
Adding to answers, If you don't want to write session_start() on starting of each and every page, You can simply skip it by setting the session.auto_start = 1
in your php.ini file , which starts the session automatically on request page.
Refer to PHP Session Configuration Documentation.
The initial file didn't contain session_start() as pointed out. however it works without it for some reason now.
I am thinking a cache or server delay issue also
Use session_start(); inside all page before using $_SESSION variable in PHP. session_start(); function use to initialize session process.
your success.php should be.
<?php
/**
* Set cookies here if/as needed.
* Set session data as needed. DO NOT store user's password in
* cookies or sessions!
* Redirect the user if/as required.
*/
session_start();
$id = $_GET['id'];
$_SESSION['partner_id'] = $id;
$_SESSION['authenticated'] = TRUE;
if (isset($_SESSION['partner_id'])) {
echo("<script>
<!--
location.replace(index.php);
-->
</script>");
}
else {
print "Session partner id not set";
}
?>
You need session_start() on all pages using $_SESSION
<?php
/**
* Set cookies here if/as needed.
* Set session data as needed. DO NOT store user's password in
* cookies or sessions!
* Redirect the user if/as required.
*/
session_start();
$id = $_GET['id'];
$_SESSION['partner_id'] = $id;
$_SESSION['authenticated'] = TRUE;
Also...are you sure that $_GET['id'] has a value in it?
And....is your form using POST or GET?
Ive made that silly mistake before , where form was using POST and I was retrieving variable with GET and getting frustrated. Just a possibility