Fog Juice Posted December 22, 2008 Share Posted December 22, 2008 Hello, I recently moved to a different dedicated server and I just compiled the latest version of php/apache. My problem now is that $_SESSION variables are being changed by $value when $value is the same name as a session value. For example <?php session_start(); $_SESSION['firstname'] = "Chris"; echo $_SESSION['firstname']; //this should say Chris. $firstname = "Jasmine"; echo $firstname; //should say Jasmine but... echo $_SESSION['firstname']; //this should say Chris but for some reason it is saying Jasmine. ?> If you notice from teh code example, $_SESSION['firstname'] is being changed by $firstname for no apparent reason. I figure it has something to do with php.ini turning something on or off. Does anyone know what to turn off so this doesn't happen? Thanks. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 You are correct, sir! Turn off register_globals in the php.ini Quote Link to comment Share on other sites More sharing options...
Fog Juice Posted December 22, 2008 Author Share Posted December 22, 2008 You are correct, sir! Turn off register_globals in the php.ini ty. Do you have a good link to securing and setting up php.ini? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 Not off of the top of my head, but I know there is a tutorial on this site that reviews the issue: http://www.phpfreaks.com/tutorial/php-security/page1 Quote Link to comment Share on other sites More sharing options...
Fog Juice Posted December 22, 2008 Author Share Posted December 22, 2008 one last question, how can I keep the same session between http://domainname.com and http://www.domainname.com? Is there a way to keep the same sesssion across an entire domain no matter what subdomain or prefix there is before the domain name? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 before you call session_start() try this... <?php ini_set('session.cookie_domain', '.domainname.com'); Note that this will share sessions between ALL subdomains of "domainname.com" including "somethingelse.domainname.com" or whatever else you may use. If you don't want to add this to every page, you can just change/add this directive in your php.ini. Quote Link to comment Share on other sites More sharing options...
Fog Juice Posted December 22, 2008 Author Share Posted December 22, 2008 before you call session_start() try this... <?php ini_set('session.cookie_domain', '.domainname.com'); Note that this will share sessions between ALL subdomains of "domainname.com" including "somethingelse.domainname.com" or whatever else you may use. If you don't want to add this to every page, you can just change/add this directive in your php.ini. I've been trying that and I can't seem to get it to work, I have it on my init.php file which is included at the very beginning of each page. When I switch from http://www.domainname.com to http://domainname.com the session does not follow. Any ideas? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 Did you try restarting your browser and/or reloading without cache? I'm not quite sure as I've never run into this problem.. if the problem persists I suppose more googling or a separate thread is in order. Quote Link to comment Share on other sites More sharing options...
Fog Juice Posted December 22, 2008 Author Share Posted December 22, 2008 Did you try restarting your browser and/or reloading without cache? I'm not quite sure as I've never run into this problem.. if the problem persists I suppose more googling or a separate thread is in order. sometimes its the dumbest things.. ty for all of your help. Quote Link to comment 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.