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' ) ; ?> 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? 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? 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? 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)]) ; ?> 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 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. 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 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)]); ?> 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
Archived
This topic is now archived and is closed to further replies.