Sessions are losting in http://www but working in http://url

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
jeh
Forum Newbie
Posts: 1
Joined: Sat Dec 06, 2008 5:35 am

Sessions are losting in http://www but working in http://url

Post by jeh »

HI,

My project have multiple modules. I have one menu it contains all module tabs. Let us,

i login in one module is called 'XXX'. Next i am going to another module is

called 'YYY' by clicking menu. In this process session values are working in

'XXX' module. But in 'YYY' module session are losting if url alike

'http://WWW.myurl' but in 'http://myurl' session values are

working. How to solve this problem ? If u have any ideas please advice me.

Thank in advance,

Suman.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sessions are losting in http://www but working in http://url

Post by requinix »

Keep the same domain name. When you make links don't include the http://yoursite.com part, just the /path/to/file.php.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Sessions are losting in http://www but working in http://url

Post by Chris Corbyn »

Sounds like your cookie is being set at www. the domain, which does not include the non www version.

You best solution is NOT to support both domain.com and http://www.domain.com, but to redirect http://www.domain.com to just domain.co, or vice -versa.

In a .htaccess file, something like this:

Code: Select all

 RewriteEngine On
 
  RewriteMap lowercase int:tolower
 
  RewriteCond %{HTTP_HOST}    ^www\.(.+)                              [NC]
  RewriteRule ^/(.*)$         http://${lowercase:%1}/$1               [R=301,L]
 
Also (without taking this too seriously ;)): http://no-www.org/
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Sessions are losting in http://www but working in http://url

Post by Kieran Huggins »

Your session is being saved to a specific subdomain - you can make your session available to all subdomains (including the root domain) by setting the cookie to ".domain.com" (notice the preceding dot?)

There are several ways to accomplish this... read: http://www.jontodd.com/2006/08/10/php-s ... e-domains/ for a few different methods.
Post Reply