I need the items in the array to be echo'd one after the other but in order and I do not want the session to be remembered.
Right now, each time I go to the URL of this script, it always starts off with "Ad2". Each time I refresh the page, it will then display Ad3, Ad4, Ad5, Ad1.
What I need is each time the webpage is opened or refreshed, whatever item in the array that is next in line to show up, will show up.
user1 goes to my webpage: Ad1 is displayed
user2 goes to my webpage: Ad2 is displayed
user3 goes to my webpage: Ad3 is displayed
user1 refreshes webpage: Ad4 is displayed
user3 refreshes webpage: Ad5 is displayed
Code: Select all
<?php // start session session_start(); $ads = array ('Ad1', 'Ad2', 'Ad3', 'Ad4', 'Ad5'); // rotate $id = ++$_SESSION['ad_id'] % count($ads); $_SESSION['ad_id'] = $id; // display ad echo $ads[$id]; ?>