sessions doesnt work with mod_rewrite

Using mod_rewrite to handle various content issues

sessions doesnt work with mod_rewrite

Postby zuly » Mon Feb 18, 2008 12:14 pm

hello everyone..
i've sucsessefully set up .htacces to change all user.php?u=username links to username.website.com and it works perfectly.
Now, i'm having a problem with sessions on that part of the website. If i create a session on, eg /home (index.php) with value "test" it works on every other part (/home,/forum,/somethingelse) but it doesn't work on profile part (username.website.com), while it works if the url of profile is website.com/user/username or even user.php?u=username.

Does anyone know how to fix this ?

ps. php.ini :
session.use_cookies On
session.use_only_cookies On
session.cookie_path /
session.cookie_domain no value
session.cookie_domain = ".website.com"

php code
Code: Select all
<?php
session_start();
//home.php
$_SESSION['username'] = "someusername";
?>
<?php
session_start();
//profile.php
echo $_SESSION['username'];
//output : nothing -.-
?>
<?php
session_start();
//forum.php
echo $_SESSION['username'];
//output : someusername
?>
zuly
 
Posts: 3
Joined: Mon Feb 18, 2008 11:48 am

Postby richardk » Mon Feb 18, 2008 3:43 pm

Try session_set_cookie_params() to set the domain parameter before session_start().

Can you set a cookie and access it yourself?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zuly » Sun Feb 24, 2008 5:38 pm

richardk wrote:Try session_set_cookie_params() to set the domain parameter before session_start().

Can you set a cookie and access it yourself?


huh, i've finally made it ! and i have no idea how :s
after removing quotes from session.cookie_domain = ".website.com" and changing it to session.cookie_domain = .website.com it's working properly (and i had to remove all caches in ff and ie too though)

(and you may already know that i can set and access to a cookie :)

and i have an another question (ill post it here so i don't have to open a new thread)

how to force "www" to all urls except the username.website.com ones ??
i've found this

Code: Select all
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]


but it always removes "www" '-,-

tnx.
zuly
 
Posts: 3
Joined: Mon Feb 18, 2008 11:48 am

Postby richardk » Mon Feb 25, 2008 4:40 pm

how to force "www" to all urls except the username.website.com ones ??

Try
Code: Select all
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zuly » Tue Feb 26, 2008 12:26 pm

richardk wrote:
how to force "www" to all urls except the username.website.com ones ??

Try
Code: Select all
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


hey, it works perfectly !!
thank you !
zuly
 
Posts: 3
Joined: Mon Feb 18, 2008 11:48 am


Return to Content

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron