Hi,
For some reason session variables aren't working for me. I checked my php info and it is on. I used the simple code on PHP's site to check if session is working, and it does not carry variables to another page. I printed session IDs and they match on both pages; just variables aren't being carried over. I'm using latest version of PHP with latest version of apache. Any ideas?
Using Session Variables
Moderator: General Moderators
Re: Using Session Variables
Code snippets of what you have would help greatly.
Always assume the code is wrong before you jump to conclusions.
Always assume the code is wrong before you jump to conclusions.
-
commandercool
- Forum Newbie
- Posts: 2
- Joined: Fri May 02, 2008 12:07 am
Re: Using Session Variables
I'm just using examples from PHP's website.
and
Code: Select all
<?php
// page1.php
session_start();
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green<br>';
$_SESSION['animal'] = 'cat<br>';
$_SESSION['time'] = time();
echo "<br>";
echo "session id: " . session_id();
echo "<br>";
echo $_SESSION['favcolor'];
echo $_SESSION['animal'];
echo $_SESSION['time'];
// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>Code: Select all
<?php
// page2.php
session_start();
echo 'Welcome to page #2<br />';
echo "<br>";
echo "session id: " . session_id();
echo "<br>";
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php">page 1</a>';
?>