I am trying to display random banner each time the user refresh the page. The problem I am facing is that I don’t want the last banner to be displayed again. I there any other way to remember the last displayed one without using cookies or database implementation?
Cookie Implementation:
<?php
$randIndex = rand(1,6);
if(!isset($_COOKIE["lastDispalyed"])){
setcookie("lastDispalyed",$randIndex,time()+60*60*24);
}
else{
while($_COOKIE["lastDispalyed"] == $randIndex){
$randIndex = rand(1,6);
}
setcookie("lastDispalyed",$randIndex,time()+60*60*24);
} ?>
<img src="images/mainBanners/<?php echo $randIndex; ?>.JPG"/>
You could use a session variable:
Reference session_start().