Forum Moderators: coopster

Message Too Old, No Replies

Sessions not working with mod rewrite

session mod rewrite

         

nquinn

6:05 am on Feb 13, 2007 (gmt 0)

10+ Year Member



Hey all,

I'm having a problem with passing sessions from one page to another. Basically, I'm trying to keep track of the last page the visitor was on in case he needs to log in.

Anyway, on my profile page, I have:

// PROFILE.PHP
session_start();
$userid = (int) $_GET['uid'];
$_SESSION['lastpage'] = "http://www.mydomain.com/user/$userid";

// LOGIN.PHP
session_start();
$lastpage = $_SESSION['lastpage'];

Now, I'm using mod_rewrite to rewrite to the profile page like this:

RewriteRule ^user\/(.*) profile.php?uid=$1

Let's assume I want to goto User ID #5's page.

If I use mydomain.com/profile.php?uid=5, and then goto the login page, the session passes properly.

However, if I use mydomain.com/user/5 , and then goto the login page, the lastpage variable shows up as follows:

[mydomain.com...]

I imagine this is some kind of mod_rewrite error, but have no idea how to fix it. Suggestions?

nquinn

4:17 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



If anyone else runs into this problem, I fixed it by using all absolute URL's.

I had referenced an image as <img src="blah.gif">, and when the server was requesting this somehow mod_rewrite was appending it to the URL.

This could probably be fixed with tighter rewrite conditions (using [L], etc)