Forum Moderators: coopster

Message Too Old, No Replies

Setting/Reading cookies problem with mod rewrite

         

georgiek50

4:09 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Hi,

I was wondering if someone can help me out on this issue.
I wrote a little PHP script that sets a cookie and then forwards the user to the appropriate page. Everything works fine until I use the mod_rewrite version of the URL. The cookie can not be read (and I don't know how to tell if it's set in the first place).

Here is some code:

linktrack.php (e.g. mydomain.com/linktrack.php?id=1)


// Get the query string value
$id = $_GET['id'];

// Set the cookie
setcookie('linktrack', $id, time()+3600*24*90);

linktracktest.php


if (!$_COOKIE['linktrack'] ) {
print 'cookie does not exist';
}

else {
$id = $_COOKIE['linktrack'];
print 'The cookie ID is: '. $id;
}

Everything works fine if I type: mydomain.com/linktrack.php?id=1 into my browser. However when I use the rewritten URL: mydomain.com/go/1 no luck.

This is my .htaccess file:


Options +FollowSymLinks
RewriteEngine on

RewriteRule ^go/(.*) linktrack.php?id=$1 [QSA]

Can anyone spot the problem here? Thanks in advance.

P.S. Please excuse the formatting. Can't get the code tags to work properly...not my day :(

WesleyC

4:34 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



To read the cookies, grab Firefox, visit your site, then go into Tools->Options, to the Privacy tab, then click "Show Cookies". You can then search through all the cookies present in the browser.

georgiek50

7:04 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Man...I wished I had posted this hours ago! Thank you! The cookie showed up in Firefox but the path was set to /go (due to mod_rewrite) and wasn't accessible...Thank you!

WesleyC

7:22 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Happy to help! :)