$_SESSION variable not passing and no clue why? it sets then doesn't pass

孤街醉人 提交于 2019-12-02 11:35:25

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

Raju

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";
}

?>

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!