Page 1 of 1

i lose session variables on redirect

Posted: Fri Aug 27, 2010 8:58 pm
by VictorFlores
i lose session variables on redirect

i have simple example

put these 2 files at the root/ in my case wamp server, the root is the www directory.

then bring up test3a.php in browser (ie or firefox)
when you click the button, session variables are set, then you get re-directed to test3b.php within same directory. . . .
but SESSION variables are not set



=================
this is test3a.php
=================

Code: Select all


<?php
	session_start();
	
	if (isset($_POST['submit']))
	{
		echo "redesplay after submit button";
		$_SESSION['test'] = 'torvic';
		//
		$root = "http://127.0.0.1/";
		header("Location: " . $root . "/test3b.php");
		die();
	}
?>	

	<form action="test3a.php" method="post">
    	  <input type="submit" name="submit" id="submit" value="Login!">
	</form>


=================
this is test3b.php
=================

Code: Select all

<?php
	session_start();

	if(isset($_SESSION['test']))
	{
		echo $_SESSION['test'];
	}
	else
	{
		echo "session var not set";
	}

	echo "<pre>";
	print_r($_SESSION);
	echo "</pre>";
?>
i do it like this:

1- bring up test3a.php in firefox 3.6.8
2- i click the "Login" button
3- i get redirected to test3b.php, but this is what i see on the browser:
<<<<<<<<<<<<<<<<<<<<<<<<<<
session var not set

Array
(
)

>>>>>>>>>>>>>>>>>>>>>>>>>>
:crazy:

Re: i lose session variables on redirect

Posted: Sat Aug 28, 2010 2:06 am
by iijb
Hi,
Try this in your $root variable

Code: Select all

$root = "http://localhost/";
Regards
iijb

that did it!! THANK YOU SO MUCH!!!

Posted: Sat Aug 28, 2010 5:43 am
by VictorFlores
Wow!

that did it!! THANK YOU SO MUCH!!!


with
http://localhost/myWeblog//test3b.php
i get:
<<<<<
torvic

Array
(
[test] => torvic
)
>>>>>>>


with
http://127.0.0.1/myWeblog//test3b.php
i get:
<<<<<
session var not set

Array
(
)
>>>>>


and this is solid!!!
:D