Problem with passing session variables
Posted: Mon May 17, 2004 5:37 pm
Hi!
I`m new to PHP and I have problem with passing session variables created with $_SESSION['variable']; on one page to another.
Here is the sample code of the first page, named page1.php:
<?php
session_start();
?>
<html>
<head><title>Page1</title></head>
<body>
<?php
$_SESSION['var1'];
header("Location: page.php?" . session_name() . "=" . session_id());
?>
</body>
</html>
and code of page 2, named page2.php:
<?php
session_start();
?>
<html>
<head><title>Page2</title></head>
<body>
<?php
echo $_SESSION['var1'];
?>
</body>
</html>
Problem is that the variable passed from page1.php in $_SESSION[] is not shown in page2.php. Session ID is passed correctly so I think it`s not a problem here for sure.
I would be very grateful for any suggestions, because it`s quite important for me to solve this problem asap (mayby I have sth wrong in php.ini - but it would be strange (I use php.ini-recomended from default windows php package).
I have PHP v4.3.4, glogals turned OFF and don`t have problem with passing header info(btw it`s interesting that even if I already sent sth info to web browser php doesn`t throw error or even warning that it cannot include header info because header information was already sent.
I`m new to PHP and I have problem with passing session variables created with $_SESSION['variable']; on one page to another.
Here is the sample code of the first page, named page1.php:
<?php
session_start();
?>
<html>
<head><title>Page1</title></head>
<body>
<?php
$_SESSION['var1'];
header("Location: page.php?" . session_name() . "=" . session_id());
?>
</body>
</html>
and code of page 2, named page2.php:
<?php
session_start();
?>
<html>
<head><title>Page2</title></head>
<body>
<?php
echo $_SESSION['var1'];
?>
</body>
</html>
Problem is that the variable passed from page1.php in $_SESSION[] is not shown in page2.php. Session ID is passed correctly so I think it`s not a problem here for sure.
I would be very grateful for any suggestions, because it`s quite important for me to solve this problem asap (mayby I have sth wrong in php.ini - but it would be strange (I use php.ini-recomended from default windows php package).
I have PHP v4.3.4, glogals turned OFF and don`t have problem with passing header info(btw it`s interesting that even if I already sent sth info to web browser php doesn`t throw error or even warning that it cannot include header info because header information was already sent.