strange mod_rewrite and SESSION problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
julian_lp
Forum Contributor
Posts: 121
Joined: Sun Jul 09, 2006 1:00 am
Location: la plata - argentina

strange mod_rewrite and SESSION problem

Post by julian_lp »

Code: Select all

in .htaccess
RewriteRule ^test_file/(.*).php /subfolder/test_file.php?arg1=blah&arg2=$1

test_file.php

<?php

	session_start();
	
       //this is the problematic line...
	echo '<img src="nonexistentpath/php_button.gif" alt="Get php"><br>';

	echo "variable $ _SESSION['xxxx'] = ".$_SESSION['xxxx'].'<br>';

	if (!isset($_SESSION['xxxx'])){
              $_SESSION['xxxx'] = 0;       
        }

       $_SESSION['xxxx']++;
	
?>

Now comes the weird beaviour:


If I call it without using the mod_rewrite, i.e

http://myip/subfolder/test_file.php

I get the expected results for the session var, which starts with 1 and after every page load adds its value 1 by 1


but, if I call it like this

http://myip/subfolder/test_file/whatever.php

$_SESSION['xxxx'] starts with 2, and then its values are 4, 6, 8 ....

Can anyone reproduce this kind of craziness, or is it just a problem with my server (local) ?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Try it with these flags on the same line as the rule: [QSA,L]
User avatar
julian_lp
Forum Contributor
Posts: 121
Joined: Sun Jul 09, 2006 1:00 am
Location: la plata - argentina

Post by julian_lp »

m3mn0n wrote:Try it with these flags on the same line as the rule: [QSA,L]
It didn't work for me :(

I'm more interested on some "explanation" for this beaviour rather than on a solution though, because the solution is simply not adding images that dont exist...
Post Reply