11

I have a interactive web site that has authors. When an author enters the site on www.mysite.com and logs in, the session varible becomes

$_SESSION[loggedid]=true;

and site-theme changes.

But when he enters mysite.com (without www's) even he is logged in, he sees the default theme, can't write etc. I think they are different sessions, am i right? Is it depends on my server or browser or what? How can i make this 2, same sessions or redirect the user's from one to one?

Wond
  • 111
  • 1
  • 2
  • 4

5 Answers5

13

Add this to your .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com$1 [R=permanent,L]
AlienWebguy
  • 73,720
  • 16
  • 109
  • 137
5

It's RewriteRule

^(.*)$ http://www.mysite.com/$1 [R=permanent,L]

and not

$1 [R=permanent,L].

If you add .com$1 [R=permanent,L] in php.ini and you try mysite.com/index.php?id=934 it redirects you to mysite.comindex.php/?id934

LPL
  • 16,007
  • 6
  • 43
  • 87
John
  • 51
  • 1
  • 1
1

Use this: http://ca3.php.net/session_set_cookie_params To set the domain to match all subdomains do this:

session_set_cookie_params($lifetime, '/', '.domain.com');

You need to use that before a calling session_start().

You could use this code example taken straight from the link above, which let's you keep all the current settings except the domain:

$currentCookieParams = session_get_cookie_params(); 

$rootDomain = '.example.com'; 

session_set_cookie_params( 
    $currentCookieParams["lifetime"], 
    $currentCookieParams["path"], 
    $rootDomain, 
    $currentCookieParams["secure"], 
    $currentCookieParams["httponly"] 
); 

session_name('mysessionname'); 
session_start(); 
Paul
  • 130,653
  • 24
  • 259
  • 248
0

Set your session.cookie_path to the domain .yourdomainname.tld, note the starting dot (.).

Wrikken
  • 64,168
  • 8
  • 83
  • 130
0
session.cookie_domain =

php.ini directive

try using

session_set_cookie_params(0, '/', '.yourdomain.com');

that leading dot means session will affect every domain. Be aware of SUHOSHIN! Sometimes it restricts this function!

genesis
  • 48,512
  • 18
  • 91
  • 118