Forum Moderators: coopster

Message Too Old, No Replies

Session not being read (mod-rewrite problem?)

Session problems

         

Frasnko

5:45 pm on May 14, 2007 (gmt 0)

10+ Year Member



Hello,
Last week i cleaned up the links on a site using mod-rewrite and this morning I discovered a curious problem. Only the site root (http://www.example.com/) maintains the session. When i click on any of the website links (www.example.com/page/30/) the session is empty, however, if i browse to the original file (page.php?id=30) the session is there.
i am completely baffled, and reading some posts (http://www.webmasterworld.com/forum88/13370.htm and <snip>) have not proved helpful in my situation.
I am thinking that the ModRewrite rules i have issued are not allowing for the PHP session to be transferred, can anyone verify this? What can i do to overcome this obstacle?

If it is of any consequence, i am using php5, and rendering the content with Smarty.
Any help or direction would be greatly appreciated.

Many thanks

[edited by: eelixduppy at 7:39 pm (utc) on May 14, 2007]
[edit reason] no URLs, please. See TOS [/edit]

phparion

6:40 pm on May 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



for cookies you might want to check the URL to read it must be an absolute path so that whatever sub level your URLs might be showing your code will read the cookie from the right place.. however for the server side sessions.... are you using session_start() before reading sessions?

just a small and quick tip to make things clear, write on top of your page (that receives values from rewrite rule)

print_r($_SESSION);

it will show you whether you have the values in SESSION array or not on different pages.

Frasnko

6:58 pm on May 14, 2007 (gmt 0)

10+ Year Member



Thank you for the reply!
I have made sure that all links have the absolute path specified.
I knew about the print_r($_SESSION) trick and have since verified that when i visit .../page/30/ there is no session (and for some reason user->login is triggered and fails since the $_POST array is enpty) but when i visit .../page.php?id=30 everything is working fine.
I have continued to search (for over 4 hours so far) and have not found any urls that speak on this specific issue.

Furthermore, when i click the link that points to to www.examplesite.com/file/ (which is a php file with the extension removed) the session is gone, but when i type the path into the address bar and hit enter it works fine!

This is nuts!

Has anyone every had this kind of stuff happen to them? Any ideas on what I can do to solve it?

Many thanks

[edited by: Frasnko at 7:30 pm (utc) on May 14, 2007]

phparion

3:36 am on May 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think server side sessions have nothing to do with URLs, can you show me your code where you read session? and where you generate session? and what way you use to register a value to sessions array and your PHP version?

Frasnko

5:34 am on May 15, 2007 (gmt 0)

10+ Year Member



Using the following rule:
RewriteRule ^portfolio/([^/]*)/image/([^/]*)/$ /image.php?cat=$1&id=$2 [L]

I transformed the URLs as such:
[....com...]
[....com...]

I was reading the session variables in several ways but the I used the following to display everything in the Session
echo "<pre>";print_r($_SESSION);echo"</pre>";

What i don't get is that I could visit the homepage, log in, and everything is fine. Then i could visit an old URL (...com/image.php?cat=fishing) and maintain the session, but if i clicked on a link to the mod re-written URLs, the page would display fine, but the session would be gone! Re-visiting the index page and everything is still there.

This is using PHP5. I have a class that wraps the session handling functions and it is included, and defined in an include (that all files have). However the instantiation of the class is only performed on login (when the form is validated).

I know for a fact that this method worked fine since i had tested it all last week (until Friday, when i implemented Mod-Rewrite).

Many thanks to all who read this and offer any advice.

phparion

5:59 am on May 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



once again, are you using session_start() on top of the page before displaying session array?

session_start();
echo "<pre>";
print_r($_SESSION);
echo"</pre>";

Frasnko

2:00 pm on May 15, 2007 (gmt 0)

10+ Year Member



Yes, of course I am using session start in the main config include (included in all the files)- well before I print out the session variables (I tested it all last week and it worked fine)!

[edited by: Frasnko at 2:06 pm (utc) on May 15, 2007]