crazy_jayne Posted February 28, 2010 Share Posted February 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/ Share on other sites More sharing options...
F00Baron Posted February 28, 2010 Share Posted February 28, 2010 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:'')); Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019379 Share on other sites More sharing options...
crazy_jayne Posted February 28, 2010 Author Share Posted February 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019458 Share on other sites More sharing options...
teamatomic Posted February 28, 2010 Share Posted February 28, 2010 in your script you can use: ini_set("session.use_trans_sid", "true"); in htaccess use session.use_trans_sid 1 HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019461 Share on other sites More sharing options...
crazy_jayne Posted February 28, 2010 Author Share Posted February 28, 2010 Hi teamatomic htaccess session.use_trans_sid 1 resulted in the page not being found at all - just goes to the error page in the script ini_set("session.use_trans_sid", "true"); seems to have no effect. Am I missing something (like some brain cells)? J Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019468 Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2010 Share Posted February 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019472 Share on other sites More sharing options...
inversesoft123 Posted February 28, 2010 Share Posted February 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019474 Share on other sites More sharing options...
teamatomic Posted February 28, 2010 Share Posted February 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193663-newbie-empty-session-help/#findComment-1019476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.