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. Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/ 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 Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721201 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? Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721203 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 Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721208 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? Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721215 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. Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721229 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? Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721247 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. Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721248 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. Link to comment https://forums.phpfreaks.com/topic/137991-solved-_sessionvalue-being-changed-by-value/#findComment-721251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.