Base URL query

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
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Base URL query

Post by someberry »

Ok, when I set a cookie, using the '/' deliminator for all subdomains etc, it only sets the cookie for http://www.site.com, and when I access it via http://site.com, it doesnt recognise it.

Does anyone have an idea of how to allow both access?
Thanks.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

From the PHP Manual
To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to http://www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the spec for details.
http://us3.php.net/setcookie
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Post by someberry »

Hmm, Im still having problems trying to get it to work in either http://site.com, and http://www.site.com - it doesnt seem to like the two, am I setting the cookie in the right way?

Code: Select all

// Prior
setcookie("c_name", "value", time()+3600, "/");

// Post
setcookie("c_name", "value", time()+3600, "/", "www.site.com");
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

It should be:

Code: Select all

setcookie("c_name", "value", time()+3600, "/", ".site.com");
Post Reply