Jump to content

How to pass session id in URL if and only if cookies are disabled?


Recommended Posts

I want to be able to have users use a site with cookies disabled, but it needs sessions. So I have been going over all of the session info in the manual trying to figure out how I add the session ID to the url when cookies are disabled.

This is what I have:

 

<?php
ini_set('session.use_trans_sid', '1');
session_start();
print session_id();
?>

 

It is my understanding that now when I click a link, the session id should be added to the URL. However, that does not happen, and the session_id is changed.

Also, if I refresh the page, a new session starts, with a new ID. None of my session data is being saved. For example if I have this:

 

<?php
if(isset($_SESSION['test'])){
print $_SESSION['test'];
}else{
$_SESSION['test'] = 'test';
}
?>

 

The first time it should show nothing, and the second time (refresh) it should show 'test'. It always shows nothing.

 

Can anyone help me figure out how to accomplish this? I don't want to force users to enable cookies, but I don't want the session id in the URL unless it has to be.

superguru jesirose,  in my opinion, if you are using any set of config.php file to store the server path, i think this is where the problem is.

 

i.e, $config_basedir = "http://127.0.0.1"  or $config_basedir="http://localhost/xyz".

 

apologize if i am wrong. 

 

Hope this helps.

regards,

 

 

hmm if you want it to be conditional tyr to set a cookie and read it imedietly, if it is not set or cant be retrieved assume that the browser wont accept it or thye have it disable, and then start passing the buck (sessionid)

That would require having every header(), every link, etc have a variable on the end of it for in case the cookie doesn't set. I thought that was the point of trans_sid, so it does it FOR you.

Just curious if you noticed this in the documentation and made sure your PHP was configured correctly:

 

PHP is capable of transforming links transparently. Unless you are using PHP 4.2.0 or later, you need to enable it manually when building PHP. Under Unix, pass  --enable-trans-sid to configure. If this build option and the run-time option session.use_trans_sid are enabled, relative URIs will be changed to contain the session id automatically.

And all of the URIs are relative?  Sorry to ask such mundane questions; I just know how easy it is when frustrated by something to overlook the minor details (that are usually right in front of my face).

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.