i lose session variables on redirect

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
VictorFlores
Forum Newbie
Posts: 2
Joined: Fri Aug 27, 2010 8:39 pm

i lose session variables on redirect

Post 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:
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: i lose session variables on redirect

Post by iijb »

Hi,
Try this in your $root variable

Code: Select all

$root = "http://localhost/";
Regards
iijb
VictorFlores
Forum Newbie
Posts: 2
Joined: Fri Aug 27, 2010 8:39 pm

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

Post 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
Post Reply