Sessions and www prefix.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Sessions and www prefix.

Post by JellyFish »

I noticed that when I set session variables on my site without the www prefix and then type in the prefix the session variables don't apply.

If you know what I mean then my question is: Is there a way let these variables exist in both instances of the URI?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

In your php.ini file you will find a line that reads something like:

; The domain for which the cookie is valid.
session.cookie_domain =

Add your domain prefixed with a . and don't forget to restart your webserver afterwards. eg:

; The domain for which the cookie is valid.
session.cookie_domain = .foo.com
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

If you dont have access to php.ini, you can achieve this by putting the below line before initializing session (session_start())

Code: Select all

ini_set ( 'session.cookie_domain', '.foo.com' );
for more info visit http://www.php.net/manual/en/ref.sessio ... kie-domain

Remember you can change most of the values of php.ini with ini_set
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Okay this is something I never really understood. What's the php.ini file?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It is php's configuration file. :arrow: http://php.net/ini
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

How do I find it on my server?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

make a blank php file, and add

Code: Select all

phpinfo()
.. it will show you the location of your php.ini. If your on a shared server, most likely you won' have access to your php.ini and would have to consult your hosting provider to request changes.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

I have this on my hosting providers help center (godaddy.com):
Godaddy wrote:Custom PHP 4 and PHP 5 initialization files You can now customize your site by creating PHP initialization files in the root of your site to manage form, server, and environmental variables, server-side cookies, temporary directories, error display, and error logging.
Is an initialization file the php.ini (does ini stand for initialization)? I assume.

I think this basically means that you can create your own and supply it to the server to your root directory, not edit the mandatory php.ini.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You got it.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Okay cool. So I found the php.ini file and what not. And I'm sure php.net has some articles on how it works.

Either ways, thanks guys.
Post Reply