Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help Refreshing Ad Rotater

    Hello. I have this code and basically what I want is that when it randomly selects to use ads_2.inc, I want to let ads_2.inc refresh once every 10 sec. Now I tried inserting a meta refresh tag into the ads_2.inc file but then sometimes it refreshes to a different ad which I do not want. Can anyone help?

    Thanks

    PHP Code:
    <?
    srand 
    ((double) microtime() * 1000000);

    $randomnumber rand(0,7);

    $include0 "ads/ads_1.inc"
    $include1 "ads/ads_2.inc"
    $include2 "ads/ads_3.inc"
    $include3 "ads/ads_2.inc"
    $include4 "ads/ads_1.inc"
    $include5 "ads/ads_2.inc"
    $include6 "ads/ads_1.inc"
    $include7 "ads/ads_2.inc"
    $include8 "ads/ads_1.inc"

    if     (
    $randomnumber== "0") {
        include (
    "$include0");

        } else if (
    $randomnumber== "1") {
        print(
    "$include1");
        
            } else if (
    $randomnumber== "2") {
        include(
    "$include2");
        
            } else if (
    $randomnumber== "3") {
        include(
    "$include3");    
        
            } else if (
    $randomnumber== "4") {
        include(
    "$include4");    

            } else if (
    $randomnumber== "5") {
        include(
    "$include5");    

            } else if (
    $randomnumber== "6") {
        include(
    "$include6");    

            } else if (
    $randomnumber== "7") {
        include(
    "$include7");    

            } else if (
    $randomnumber== "8") {
        include(
    "$include8");        
        
        } else {
        
        echo (
    "ERROR: A random num is being generated out of range, or not at all ");    
        }
    ?>

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    main file
    PHP Code:
    <?
    if( !isset($_REQUEST['refresh']) || $_REQUEST['refresh'] == '0' ){
    srand ((double) microtime() * 1000000);

    $randomnumber rand(0,7);
    $include = array();
    $include[0] = "ads/ads_1.inc"
    $include[1] = "ads/ads_2.inc"
    $include[2] = "ads/ads_3.inc"
    $include[3] = "ads/ads_2.inc"
    $include[4] = "ads/ads_1.inc"
    $include[5] = "ads/ads_2.inc"
    $include[6] = "ads/ads_1.inc"
    $include[7] = "ads/ads_2.inc"
    $include[8] = "ads/ads_1.inc"

    if( (
    $randomnumber >= 0) && ($randomnumber <= 8) ){
      include(
    $include[$randomnumber]);
    }
    }
    ?>
    now when you refresh the page using the meta tags just refresh the page loading it with

    www.yoursite.com/yourpage.php?refresh=1

    and when you want the add to rotate

    www.yoursite.com/yourpage.php
    or
    www.yoursite.com/yourpage.php?refresh=0
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks but only thing is that it doesnt refresh. Could there be something wrong?

    EDIT: nvm I got it.
    Thanks
    Last edited by IndianProxy.com; 01-01-2006 at 11:16 PM.

  • #4
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    PHP Code:
    $randomnumber mt_rand(0,7);
    $include = array();
    $include[0] = "ads/ads_1.inc"
    $include[1] = "ads/ads_2.inc"
    $include[2] = "ads/ads_3.inc"
    $include[3] = "ads/ads_2.inc"
    $include[4] = "ads/ads_1.inc"
    $include[5] = "ads/ads_2.inc"
    $include[6] = "ads/ads_1.inc"
    $include[7] = "ads/ads_2.inc"
    $include[8] = "ads/ads_1.inc"

      if(
    $randomnumber == || $randomnumber <= count($include)) ){
        include(
    $include[$randomnumber]);
      }
    }

    ?> 
    That edit will give you less to edit if you take away array values, or add new ones, so you don't have to edit anything but the array.

    and you might look into array_rand()
    Last edited by Element; 01-01-2006 at 11:59 PM.

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $include 
    = array();
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_3.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc";

    include(
    $include[array_rand($include)]);

    ?>
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Velox Letum
    PHP Code:
    <?php
    $include 
    = array();
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_3.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc"
    $include[] = "ads/ads_2.inc"
    $include[] = "ads/ads_1.inc";

    include(
    $include[array_rand($include)]);

    ?>
    See, it is allot more simple with array_rand(), its also quite usefull since manipulating random array results the long way just takes up more time and may not be as fast.

    Only problem with that is unless you want more code then you might take out the last array result because it doesn't look like you were using it.

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you are all focusing on cleaning up the array - the problem was with the refreshing.

    I suggest you use url variables.

    so....

    PHP Code:

    if(isset($_REQUEST['ad']) && ($_REQUEST['ad'] == || $_REQUEST['ad'] < count($includes))){

    include(
    $includes[$_REQUEST['ad']]);

    } else {

    run the random add select code


    then in the meta tag - when you refresh

    call

    myPage.php?ad=(Array key for said ad)
    *without the perenthesis.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #8
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Yes, we were adding alternate advice for functionality, and quicker parsing.


  •  

    Posting Permissions

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