Jump to content

Newbie: empty session help


crazy_jayne

Recommended Posts

Hi

 

When I run the example script below it only works if my cookies are enabled.  What do I need to change to allow it to work if cookies are disabled, is there a server setting somewhere I need to change?

 

<?php

session_start();

 

if(isset($_SESSION['views']))

$_SESSION['views']=$_SESSION['views']+1;

else

$_SESSION['views']=1;

echo "Views=". $_SESSION['views'];

?>

 

Thanks

Crazy

Link to comment
Share on other sites

If cookies are disabled and trans sid is on, PHP will add the session ID automatically to the end of links(long ugly URLs) and in forms.

Turn it on in php.ini or .htaccess or like this:

ini_set("session.use_trans_sid", "true");

It does most of the work but you still have to do things like this:

header('Location: somepage.html');

you have to change to:

header('Location: somepage.html' . ((defined(SID))?'?' . SID:''));

 

 

Link to comment
Share on other sites

Hi F00Baron

 

Thanks for your reply.

I tried putting ini_set("session.use_trans_sid", "true"); in an .htaccess file but it resulted in the page not being found at all and going to an error page.  I don't think I have access to the php.ini file.

 

I had a look around and found some examples of where that code had been put in the file itself but when I tried it nothing happened.

I have checked my php settings PHP Version 4.4.9 and session.use_trans_sid and it is set to off not true or false.  Is it anything to do with the version of PHP?

 

Any help appreciated

 

Link to comment
Share on other sites

You can only put php setting into a .htaccess file when php is running as an Apache server module. If php is running as anything else, they result in an internal server error.

 

To use session.use_trans_sid, you must do more than simply turn the setting on, because php will only append the session id onto the end of the URL in a limited number of cases.

 

Do you have a specific reason you are attempting to use sessions without passing the session id using a cookie?

Link to comment
Share on other sites

If cookies are disabled and trans sid is on, PHP will add the session ID automatically to the end of links(long ugly URLs) and in forms.

Turn it on in php.ini or .htaccess or like this:

ini_set("session.use_trans_sid", "true");

It does most of the work but you still have to do things like this:

header('Location: somepage.html');

you have to change to:

header('Location: somepage.html' . ((defined(SID))?'?' . SID:''));

 

Probably you are on SuPHP enabled server.. batter contact your host :)

Link to comment
Share on other sites

No, I would at this point not figure a lack of gray matter to be the problem. ;)

 

Most likely is that you are not allowed to override php.ini settings and session.use_trans_sid is turned off for security reasons.

 

If you are building the site from scratch and are just starting you can just do it yourself. Its a bit more hassle in the coding but not at all difficult. Just append the sessionID to all internal links and then use a get to pull the correct session out  and initiate it.

 

 

HTH

Teamatomic

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.