Jump to content

[SOLVED] $_SESSION['value'] being changed by $value


Fog Juice

Recommended Posts

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.

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?

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.

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.