Code: Select all
<?php
// page1.php
session_start();
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
echo '<br /><a href="page2.php">page2</a>';
?>Code: Select all
<?php
// page2.php
session_start();
echo 'Welcome to page #2<br />';
if (isset($_SESSION['favcolor'])){
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
}else{
exit(0); //SESSION vars is not set.
}
echo '<br /><a href="page1.php">page1</a>';
?>1) load the page1.php
1.1) SESSION vars was created and initialized.
2) click the page2 link
3) load the page2.php
4) echo SESSION vars.
Problem: SESSION vars is always unavailable. Therefore, exit(0) is always executes.
Please help me to use SESSION vars and also the same problem with global vars. It always set to nothing the previously set the value in other pages then when the time I access the global vars, it always no value (isset() function is always false).
rozvin marchan
student
shizuoka-ken, fuji-shi, japan