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! Link to comment https://forums.phpfreaks.com/topic/195853-php-code-help-simple-url-rotator/ 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? Link to comment https://forums.phpfreaks.com/topic/195853-php-code-help-simple-url-rotator/#findComment-1028781 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)]; Link to comment https://forums.phpfreaks.com/topic/195853-php-code-help-simple-url-rotator/#findComment-1028784 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! Link to comment https://forums.phpfreaks.com/topic/195853-php-code-help-simple-url-rotator/#findComment-1028790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.