Mohamed  Kira Mohamed Kira - 3 months ago 8
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

index.php

<?php

session_start();

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


session.php looks like

<?php
session_start();
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
session.use_trans_sid=1

Answer

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.

Link: http://stackoverflow.com/a/3740866/6622577