Mohamed  Kira Mohamed Kira - 5 months ago 14
PHP Question

passing session variables with cookies turned off

im trying to pass session variable across the two pages i created, with the cookies turned off on my browser (firefox latest version), but im getting error here is my code




$_SESSION['name'] = "bob";
go to next page <a href="session.php?<?php echo SID; ?>">click

session.php looks like

echo $_SESSION['name'];

obviously php couldn't recognize the $_SESSION['name'] index and output the following error

Notice: Undefined index: name inC:\xampp\htdocs\S2\session.php on line 3

note: ive enabled the trans_sid on the php.ini file


I recreated your scenario and what worked for me was putting these settings before the session_start():

 ini_set("session.use_cookies", 0);
 ini_set("session.use_only_cookies", 0);
 ini_set("session.use_trans_sid", 1); // well you can leave this since you have it already in php.ini
 ini_set("session.cache_limiter", "");

I hope this solves your problem. Of course you can edit your php.ini too instead of hardcoding this.

What I like to add is that using trans_sid can create a security hole if someone gets your session id. Do some IP check before and limit access to only the IP that created the session id. Keep in mind that using trans_id can also break your app if using an old link with old session id.