anyone with a simple php script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sexymail
    So Fucking Banned
    • Feb 2002
    • 350

    #1

    anyone with a simple php script?

    I need a php script that will split my hits between 2 urls. for example.
    1 hit in = redirects to url 1
    another hit in = redirects to url 2
    another hit in = redirects to url 1
    so on and so forth......
  • Cirrus
    Confirmed User
    • Feb 2002
    • 1145

    #2
    PHP Code:
    <?
    $url=Array(
      "http://site1.com",
      "http://site2.com"
    );
    
    
    
    $filename="count.txt";
    if (file_exists($filename)):
        $file=file($filename);
        $hits=intval($file[0])+1;
        $fp=fopen($filename,"w+");
    else:
        $fp=fopen($filename,"w");
        $hits=0;
    endif;
    if ($hits>=count($url)) $hits = 0;
    fputs($fp,"$hits\n");
    fclose($fp);
    
    header("Location: $url[$hits]");
    
    
    ?>
    set appropriate CHMOD to count.txt -
    I do not claim that this is the best solution
    Reyko.com - exclusive glamour production icq:35570298

    Comment

    • Sexymail
      So Fucking Banned
      • Feb 2002
      • 350

      #3
      thank you

      Comment

      • KC
        Confirmed User
        • Jan 1995
        • 2417

        #4
        PHP Code:
        
        <?
                $url1 = "http://www.myfirsturl.com/?mycode";
                $url2 = "http://www.mysecondurl.com/?myothercode";
                
                if (((date("s") + 1) % 2) == 0) {
                        // even # of seconds
                        $location = $url1;  
                } else {
                        // odd # of seconds
                        $location = $url2; 
                }
                 
                header("Location: $location");
        ?>

        Here's a quick and dirty UNTESTED! way to do it...

        If you only want to redirect between 2 URLs and you want to keep them pretty even but not necessarily EXACTLY even, I would do something like that that didn't involve file I/O... any time you touch the disk it's going to get slow especially if you're going to throw a lot of traffic at it.

        This just checks to see if the current second is even or odd and then forwards to either url1 or url2...

        If you're only talking about 2 URLs and not needing to track any stats, I'd say something like this would work pretty damn well. \

        So just copy that code into a php file, update the 2 urls and send traffic directly to the php page you create.

        Good Luck!
        -KC

        Jupiter Hosting, Inc.
        Vice President, Business Development
        kc (AT) jupiterhosting.com

        Comment

        • Sexymail
          So Fucking Banned
          • Feb 2002
          • 350

          #5
          thx fellas, i went with KC's seems to be working great sofar
          i appreciate the input

          Comment

          • 4Pics
            Confirmed User
            • Dec 2001
            • 7952

            #6
            What's wrong with how i am doing it


            <?

            $urls = array(
            1 => "http://www.url1.com",
            2 => "http://www.url2.com",
            3 => "http://www.url3.com",
            4 => "http://www.url4.com",
            );

            srand ((double) microtime() * 1000000);
            $randnum = rand(1,4);
            $goto = $urls[$randnum];

            header("Location: $goto");

            ?>
            Last edited by 4Pics; 03-26-2002, 10:45 PM.

            Comment

            • KC
              Confirmed User
              • Jan 1995
              • 2417

              #7
              4Pics,

              Your's will work well also...

              For something simple like this, as long as it isn't hitting a database or reading & writing to a text file, just about ANYTHING will work...

              -KC

              Jupiter Hosting, Inc.
              Vice President, Business Development
              kc (AT) jupiterhosting.com

              Comment

              • Big E
                Registered User
                • Mar 2002
                • 935

                #8
                I dunno what you're using this for, but you might consider stashing a cookie so that if/when the user/visitor ever comes back, he gets the alternate URL on the second visit.

                Then you can do a "porn site" Survivor test where you can run 3-4-5 front ends, all receiving equal amounts of traffic and figure out which one is doing worst - pull it out, redesign it and put it back in the rotation and repeat.

                Comment

                • zubr
                  Confirmed User
                  • Jan 2002
                  • 1227

                  #9
                  Do it with java script - no server load + it will work for 99% of browsers.... if a simple java script wont work on the user, how can you expect a sponsor to track the signup??
                  Alex - ICQ:61889253 - MSN:zubr_zubr at hotmail.com - Skype:zubrzubr

                  Comment

                  • KC
                    Confirmed User
                    • Jan 1995
                    • 2417

                    #10
                    Do it with java script - no server load + it will work for 99% of browsers.... if a simple java script wont work on the user, how can you expect a sponsor to track the signup??
                    99% of browsers have javascipt... but how many have JS, but have it disabled?

                    I think relying on a browser to do a rotation job is unreliable. Especially when you have a fast server side technology like PHP available to you. (as this guy did)

                    PHP doing something like this could easily hanle millions of hits per day, depending on the hardware. Speed and server load won't be a problem with something like this.

                    -KC

                    Jupiter Hosting, Inc.
                    Vice President, Business Development
                    kc (AT) jupiterhosting.com

                    Comment

                    • Sexymail
                      So Fucking Banned
                      • Feb 2002
                      • 350

                      #11
                      Yeah, i thought about javascript, but like you say most asswipes have it off or its not supported in some way, so php seemed like the only way togo, as far as cookies go, these visitors will only hit the site once (98% sure of that) so no need to stick a big fat nasty cookie in thier pc

                      Comment

                      • KC
                        Confirmed User
                        • Jan 1995
                        • 2417

                        #12
                        no need to stick a big fat nasty cookie in thier pc
                        I think everyone should just set as many damn cookies as possible!! ;)

                        Jupiter Hosting, Inc.
                        Vice President, Business Development
                        kc (AT) jupiterhosting.com

                        Comment

                        Working...