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.
Problem with passing session variables
Moderator: General Moderators
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
make a php file and stick in it
then look at it and see what it says about your server's session setup, some servers may have sessions set up differently depending on how they were configured when the server was set up.....
---good luck---
Code: Select all
<?php
php_info();
?>---good luck---
I solved the problem
Thank you VERY VERRRRRY MUCH 
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
and once you start getting the lovely:
headers already sent errors/warnings
move the header() call and it's requirements to just after the session_start() call.
headers already sent errors/warnings
move the header() call and it's requirements to just after the session_start() call.
Code: Select all
<?php session_start(); ?> <html> <head><title>Page1</title></head> <body> <?php $_SESSION['var1']; header("Location: page.php?" . session_name() . "=" . session_id()); ?>