GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   anyone with a simple php script? (https://gfy.com/showthread.php?t=54759)

Sexymail 03-26-2002 06:15 PM

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 03-26-2002 07:11 PM

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 :)

Sexymail 03-26-2002 08:17 PM

thank you:)

KC 03-26-2002 08:21 PM

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

Sexymail 03-26-2002 10:45 PM

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

4Pics 03-27-2002 12:43 AM

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");

?>

KC 03-27-2002 12:54 AM

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

Big E 03-27-2002 07:46 AM

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.

zubr 03-27-2002 08:57 AM

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?? :)

KC 03-27-2002 01:29 PM

Quote:

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

Sexymail 03-27-2002 03:41 PM

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:)

KC 03-27-2002 03:42 PM

Quote:

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


All times are GMT -7. The time now is 12:48 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123