Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Random Affiliate

  1. #1
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Random Affiliate

    is there a very simple and small script to randomly select an affiliate banner and rotate it everytime the page is loaded i found a few but they have like 50 lines of codes,i use to use one a few yrs ago that was just 5 lines and was a simple <ahref="link"><img src='imgurl"> with 3 lines ontop and 2 under.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Rotating a banner each time the page loads is kinda bad. Make sure the filesize is small enough... or it will really slow down the users on slower connections.

    You might want to use cookies/sessions to keep track of the one that user got and keep it the same through a whole session on your site.
    (or maybe you need them to see all the choices as they browse around)

    Could you use php? Not that hard in that, just don't know the code in JS.

    PHP Code:
    top of your page:
    <?php
    $array
    [0] = "insert tags here";
    $array[1] = "more here";
    //add entries as you please
    $thing $array[rand(0,1)]; //note that the 1 is to be replaced with the highest number above in the array list.
    ?>

    then in your content, put this:
    <?php echo $thing?>
    You could code something similar in javascript, but I don't know the codes right now... you could look them up. Use arrays (note the $ is only used in php... no need for it in javascript), use a random number, then just change somethign on the page to the random number entry of the array. That's it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well yeah i think i could use php just that i know more about JS,in this part here where would i put the image url and where would i put the linkmsomething like :
    <?php
    $array[0] = "imageurl.gif,http://linktogoto.com";
    $array[1] = "more here";

    And that session part sounds really interesting,how would i insert it into this script? i heard of them before and seen some use it but never though of addin it to the ratating banners,thxs for the help

    Mav

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    At the very top of your page, before anything else (including whitespace):
    Code:
    <?php
      error_reporting(E_ALL);
      session_start();
    
      $image = array(
        array(
          'image' => 'imageurl.gif',
          'link' => 'http://linktogoto.com'
        ),
        array(
          'image' => 'imageurl.png',
          'link' => 'http://anotherlinktogoto.com'
        ),
        array(
          'image' => 'imageurl.jpg',
          'link' => 'http://yetanotherlinktogoto.com'
        )
      );
    
      if(!isset($_SESSION['curimg']))
        $_SESSION['curimg'] = rand(0, count($image) - 1);
    
      $image = $image[$_SESSION['curimg']];
    
      $image = '<a href="' . $image['link'] . '"><img src="' . $image['image'] . '"></a>';
    ?>
    Where you want the image to appear:
    Code:
    <?php echo($image); ?>
    That will keep the banner the same for each user who visits your site, as per djr33's idea.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe sessions are only server side, or at least limited using javascript. (you could use a cookie instead, or something, I guess)

    php is a good language to learn.
    (And, for me, javascript is a good language to learn)
    so.. I do understand where you're coming from.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    that seems like a great script idea to get the images catched in the cache,i tried Twey's script and it displays the image but only the first one then i reloaded several times and it doesn't make it rotate?

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    twey's script DOESN'T rotate based on refreshing. That's the point of sessions.

    It will keep the banner the same, so it doesn't need to reload each time and slow down transfers of the pages.

    It will be random at the start of each visit, then stay the same throughout the visit.

    Taking that out would be easy, but it's certainly worth considering... will be a LOT nicer for dialup users.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh ok but it will change once you close to browse and revist?then thats fine another thing,is it possible to open the link in a new windows maybe something like :

    $image = array(
    array(
    'image' => 'imageurl.gif',
    'link' => 'http://linktogoto.com' target='_blank' ?

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      $image = '<a href="' . $image['link'] . '" target="_blank"><img src="' . $image['image'] . '"></a>';
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey,

    I'v been using this script for a while and it works awesome but sometimes this error comes up:

    Notice: Undefined index: curing in /home/.foobar/dexter/ads/rightad.php on line 195

    Line 195 is $image = $image[$_SESSION['curimg']];

    Or Notice: Undefined offset: 65 in /home/.foobar/dexter/ads/rightad.php on line 195

    Does anyone know why? Thanks

Bookmarks

Posting Permissions

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