Jump to content

php code help - simple URL Rotator


dombrorj

Recommended Posts

I'm trying to use the following URL rotator, but it only works about 1 out of every 3-4 times its executed. Otherwise it does nothing. Just gets stuck at the "link.php" pages and returns a a blank, white page instead of doing the header redirect.

 

<?php

$variable = $_GET['variable'];

$offers = array (
"link1.php?variable=$variable",
"link2.php?variable=$variable",
"link1.php?variable=$variable"
);

{
$url = $offers[rand(-1, count($offers) + 1)];
header("Location: $url");
}

?>

 

Any ideas what I'm doing wrong here?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/195853-php-code-help-simple-url-rotator/
Share on other sites

Better yet... I have this script, which is a sequential rotator. Works perfectly, but I need to append a variable to the end of the URLs in "links.txt"

 

So httx://mysite.com/rotate.php?variable=123. Need to Get that variable and add it to the end of the URLs.

 

rotate.php looks like this

$linksfile ="./links.txt";
$links = file("$linksfile");

$use_this=array_shift($links);//take a line to use from the top

array_push($links,$use_this);// puts the line back on the bottom

trim("$use_this");//remove new line character from end of line

file_put_contents("$linksfile","");//empty the links file

foreach($links as $link)//loop through the links array
{
file_put_contents("$linksfile","$link",FILE_APPEND);//append the links to the linksfile
}
echo "<a href=\"$use_this\">$use_this</a>"; //echo the link

 

links.txt

http://link1.com?variable=
http://link2.com?variable=
http://link3.com?variable=

 

Any idea how I could do that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.