I wrote a simple session based image rotator that was intended to work as follows:
- - When the user visits the site a session is created
- A random image is selected and the name of the image is stored in the session
- This image is displayed on the home page of the site
- The user may navigate away from the home page, but on subsequent visits to the home page within the same session, the same image is displayed.
Code: Select all
<?php
session_start();
$imagesArray = array("img01.jpg", "img02.jpg", "img03.jpg");
if(isset($_SESSION["newImg"])){ /* do nothing */ }
else{ $_SESSION["newImg"] = $imagesArray[rand(0,(sizeof($imagesArray)-1))]; }
?>
<img src="<?php echo $_SESSION["newImg"];?>" />I compared the phpinfo page on my local install against the host, and the settings are very much the same. 5.1.2 seems to have a few more variables, but other than that, no glaring differences. Has anyone ever had a similar problem?As of PHP 4.1.0, $_SESSION is available as a global variable just like $_POST, $_GET, $_REQUEST and so on...
Thanks,
~jeff