SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    0 Post(s)
    0 Thread(s)

    image rotatator (show new image each time when browsing pages)

    I have a side column area on my site (on all pages) and a bunch of images (11).

    When someone moves to a new page a new image should display until all 11 have shown and then loop..

    Can somone suggest a simple means of doing this? I imagine that sessions and some sort of array will be needed?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Bloomington, IL
    0 Post(s)
    0 Thread(s)
    You could use sessions or cookies. The easiest way to do this would to have every page check if the session variable or cookie exists. If not, it should create a variable or cookie with value "1". If the cookie or variable does exist, it should increase its value by one. You can use this value to load the corresponding image (for example, img1.gif...img11.gif, just substituting the value of the variable or cookie for the number.). Once the number reaches 11, have it reset back to 1. Here is an example using cookies:
    PHP Code:
    if(!is_int($_COOKIE["imgNumber"])){ //Check if the cookie already exists
       setcookie("imgNumber", 1); //If not, create it and set it to 1
    }else{ //If the cookie does already exist
       $nextNumber = $_COOKIE["imgNumber"] + 1; //Find the next number to set
       if($nextNumber > 11) $nextNumber = 1; //If we've reached the end, start over
       setcookie("imgNumber", $nextNumber); //Set the next number
    And for the image:
    HTML Code:
    <img src="images/img<?php echo $_COOKIE["imgNumber"]?>"></img>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts