Can anybody please help me with a script

Discussion in 'PHP' started by crookboy, Feb 27, 2011.

  1. #1
    I am running an image site.I need a script that can change the ad after each page refresh.I mean i am running 3 ad services.if 1 ad service is displayed in one page view,next time when the same user views the page,the ad displayed should be the ad from another service.Is that possible?Can anyone provide me with a working script for that?
     
    crookboy, Feb 27, 2011 IP
  2. jareso

    jareso Well-Known Member

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #2
    I wrote a little script based on cookies for You.
    The code is pretty self-explaining.

    
    <?php
      $ad_mem = "ad_1"; // First time ad_1, if no cookie is set
      if (isset($_COOKIE['ad_mem']))
        $ad_mem = $_COOKIE['ad_mem']; // Else use cookie value
    
      if ($ad_mem == 'ad_1')
      {
      	// Show ad 1
        echo "<a href=\"#\"><img src=\"img/img_ad_1.jpg\" alt=\"Advertisement 1\" title=\"Advertisement 1\"></a>";
      	// Change to 2 advertisement for next time
      	setcookie("ad_mem", "ad_2");
      }
      if ($ad_mem == 'ad_2')
      {
      	// Show ad 2
        echo "<a href=\"#\"><img src=\"img/img_ad_2.jpg\" alt=\"Advertisement 2\" title=\"Advertisement 2\"></a>";
      	// Change to 3 advertisement for next time
      	setcookie("ad_mem", "ad_3");
      }
      if ($ad_mem == 'ad_3')
      {
      	// Show ad 3
        echo "<a href=\"#\"><img src=\"img/img_ad_3.jpg\" alt=\"Advertisement 3\" title=\"Advertisement 3\"></a>";
      	// Change back to 1 advertisement for next time
      	setcookie("ad_mem", "ad_1");
      }
    ?>
    
    Code (markup):
    Enjoy! ;)
     
    jareso, Feb 27, 2011 IP