Jump to content

How To Make More Than One Redirection with PHP on the same page?


Darkwoods

Recommended Posts

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' ) ;

?>

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?

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)]) ;
?>

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

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.

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)]);
?>

Archived

This topic is now archived and is closed to further replies.

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