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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.