Jump to content

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


Jessica

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.