1

My php sessions when logged in will not display my links when I type the following url in the browser example.com but will display the links when I type www.example.com how can I fix this problem if possible?

wer
  • 11
  • 1
  • possible duplicate of [Allow php sessions to carry over to subdomains?](http://stackoverflow.com/questions/644920/allow-php-sessions-to-carry-over-to-subdomains) – casablanca Dec 01 '10 at 19:02

2 Answers2

3

This is because the sessions are only for one or the other. What you could do, is only allow users on either www.example.com or example.com . To set this up just add this code into your .htaccess

# non-www redirect
 RewriteCond %{HTTP_HOST} !^example\.com$
 RewriteRule (.*) http://example.com/$1 [R=301,L]

This will then redirect any people to example.com if they try and get onto www.example.com

If you have a .co.uk domain this may help

 # non-www redirect
 RewriteCond %{HTTP_HOST} !^example\.co\.uk$
 RewriteRule (.*) http://example.co.uk/$1 [R=301,L]

There is another way to do it via sessions over sub-domains. See this for more info

Hope it helps!

ryryan
  • 3,890
  • 13
  • 43
  • 72
1

you have coded your sessions with 'www.' that is why they do this. You can make the changes in yoru session code or perhaps use a 301 redirect in your .htaccess to direct example.com to www.example.com automatically.. also this redirection method is SEO friendly.

hope that helps

Ayaz Malik
  • 148
  • 1
  • 12