php help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ztik
    Confirmed User
    • Aug 2001
    • 5196

    #1

    php help

    so I am trying make a script that will goto 1 url or the other randomly

    I figured I would make it select a random number then if $num = 1 goto www.google.com and if $num = 2 then goto www.yahoo.com

    I can't seam to get it to work I can however get the number part to work


    <?php

    $num = mt_rand(1, 2);
    echo($num);



    ?>



    how would I go about finishing that?
    .
  • calmlikeabomb
    Confirmed User
    • May 2004
    • 1323

    #2
    PHP Code:
    <?php
    
    ob_start();
    
    list($num, $url) = array(mt_rand(0, 1), array('http://www.yahoo.com/', 'http://www.google.com/'));
    
    header("Location: $url[$num]"); ob_flush(); exit();
    
    ?>
    Use the url array to store the address you want to redirect to. The first parameter of mt_rand() must be zero, because the first index of an array is always 0 then, 1, 2, 3, etc. You'll want the second parameter to be total number items in the array. Don't forget the first item in the array is indexed as 0.
    subarus.

    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      Levi can you msg me i been trying to reach you for over a week
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • fluffygrrl
        So Fucking Banned
        • May 2006
        • 2187

        #4
        What he said. Not sure you actually need the ob_start, you could echo a javascript redirect, depending what works for you.

        Comment

        • calmlikeabomb
          Confirmed User
          • May 2004
          • 1323

          #5
          @Fris, yeah I got your support ticket this morning. Haven't been on AIM much and had to disconnect my phone lines. College semester started 2 weeks ago been keeping me busy that's all..

          @fluffygrrl, You don't in that example, but it's still good practice.
          subarus.

          Comment

          • fris
            Too lazy to set a custom title
            • Aug 2002
            • 55679

            #6
            can you please hit me up when you can? thanks
            Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

            Comment

            • BIGTYMER
              Junior Achiever
              • Nov 2004
              • 17066

              #7
              PHP Code:
              <?php
              $url1 = 'http://www.google.com';
              $url3 = 'http://www.yahoo.com';
              $lnk = array(); 
              $lnk[count($lnk)] = $url1;
              $lnk[count($lnk)] = $url2;
              $count = count($lnk); $i = date(s); $i = $i%$count; if($lnk[$i]){ $url = $lnk[$i]; } else { $url = $url1; }
              header( "Location: ". $url );
              ?>
              I'm not 100% sure what you need. That is one way to do it.

              Comment

              Working...