Darkwoods Posted December 10, 2009 Share Posted December 10, 2009 Hey im trying to do a direction page where it open differently link direction pages every time somebody enter it.. like this for example any good hint on how to do this? <?php header( 'Location: http://www.site1.com/new_page.html' ) ; header( 'Location: http://www.site2.com/new_page.html' ) ; header( 'Location: http://www.site3.com/new_page.html' ) ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/ Share on other sites More sharing options...
Graxeon Posted December 10, 2009 Share Posted December 10, 2009 Are you asking?: How do I redirect to a random link every time the page is viewed? Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974426 Share on other sites More sharing options...
Darkwoods Posted December 10, 2009 Author Share Posted December 10, 2009 Are you asking?: How do I redirect to a random link every time the page is viewed? yes please how can i do that? Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974621 Share on other sites More sharing options...
oni-kun Posted December 10, 2009 Share Posted December 10, 2009 Are you asking?: How do I redirect to a random link every time the page is viewed? yes please how can i do that? Easy and fun..:' <?php $rand = rand(1,3); //For random selection if ($rand == "1") { header( 'Location: http://www.site1.com/new_page.html' ) ; } elseif ($rand == "2") { header( 'Location: http://www.site2.com/new_page.html' ) ; } else { header( 'Location: http://www.site3.com/new_page.html' ) ; } ?> Simple enough, eh? Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974625 Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 This method is simpler, more versatile and syntactically correct. <?php $arr = array( 'http://www.site1.com/new_page.html', 'http://www.site2.com/new_page.html', 'http://www.site3.com/new_page.html' ); header('Location: '. $arr[rand(0,count($arr)-1)]) ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974627 Share on other sites More sharing options...
oni-kun Posted December 10, 2009 Share Posted December 10, 2009 This method is simpler, more versatile and syntactically correct. <?php $arr = array( 'http://www.site1.com/new_page.html', 'http://www.site2.com/new_page.html', 'http://www.site3.com/new_page.html' ); header('Location: '. $arr[rand(0,count($arr)-1)]) ; ?> So is your mother Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974630 Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 This method is simpler, more versatile and syntactically correct. <?php $arr = array( 'http://www.site1.com/new_page.html', 'http://www.site2.com/new_page.html', 'http://www.site3.com/new_page.html' ); header('Location: '. $arr[rand(0,count($arr)-1)]) ; ?> So is your mother Well said. Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974631 Share on other sites More sharing options...
Darkwoods Posted December 10, 2009 Author Share Posted December 10, 2009 thank you all Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974639 Share on other sites More sharing options...
thebadbad Posted December 10, 2009 Share Posted December 10, 2009 Using array_rand() instead of rand() and count(): <?php $arr = array( 'http://www.site1.com/new_page.html', 'http://www.site2.com/new_page.html', 'http://www.site3.com/new_page.html' ); header('Location: ' . $arr[array_rand($arr)]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/184580-how-to-make-more-than-one-redirection-with-php-on-the-same-page/#findComment-974648 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.