sessions are different if url has www. in front

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
tehhparadox
Forum Newbie
Posts: 18
Joined: Thu Oct 01, 2009 11:55 am

sessions are different if url has www. in front

Post by tehhparadox »

Hi all,

There's something quite annoying about sessions - that is, I think the sessions are different for http://example.com and http://www.example.com.
If sessions are set in one, it is not set in the other.
This can get very annoying. Is there a way around this?
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

Re: sessions are different if url has www. in front

Post by Tiancris »

Yep, you're right. Same thing happened to me and I've solved adding a redirect from http://domain to http://www.domain.
This way you ensure that the site is navigated always in the same url.

I made this redirections using cPanel, and the result is something like this (htaccess file):
[text]RewriteCond %{HTTP_HOST} ^blablabla.com.ar$
RewriteRule ^(.*)$ "http\:\/\/www\.blablabla\.com\.ar\/$1" [R=301,L][/text]

And works in all this cases:
[text]http://blablabla.com.ar =====> http://www.blablabla.com.ar
http://blablabla.com.ar/item.php =====> http://www.blablabla.com.ar/item.php
http://blablabla.com.ar/item.php?id=15 =====> http://www.blablabla.com.ar/item.php?id=15[/text]
Post Reply