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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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