dombrorj Posted March 19, 2010 Share Posted March 19, 2010 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! Quote Link to comment Share on other sites More sharing options...
dombrorj Posted March 19, 2010 Author Share Posted March 19, 2010 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? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 19, 2010 Share Posted March 19, 2010 Either one of these $url = $offers[rand(0, count($offers)-1 )]; $url = $offers[array_rand($offers,1)]; Quote Link to comment Share on other sites More sharing options...
dombrorj Posted March 19, 2010 Author Share Posted March 19, 2010 Either one of these $url = $offers[rand(0, count($offers)-1 )]; $url = $offers[array_rand($offers,1)]; Excellent! Thanks teamatomic. That's your script above, which you helped me out with before. I appreciate it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.