Jump to content

PHP Redirection


mythsmx

Recommended Posts

Hi, please please help with this PHP code. Essentially, this PHP page will be stored on Server1. It will function as a redirect to another server. ServerA is the Primary, while ServerB is the secondary. If the Primary fails, the PHP page should redirect the access to ServerB url.

 

I tried this and the redirection works only for the Primary. I also tried several attempts to put an invalid host for the Primary, but it seems like the ELSE condition does not work. Please help me how to fix this. Thank you very much.

 

 

<?php

$Pri = "http://www.yahoo.com";

$Sec = "http://www.google.com";

 

//check for port number, default is 80

$link = $_GET['link'].":";

$s_link = str_replace("::", ":", $link);

list($addr,$port)= explode (':',"$s_link");

if (empty($port)){

$port = 80;

}

//Test the server connection

$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);

if (!$churl){

//echo $errstr;

header("Location: $Pri");

}

else {

header("Location: $Sec");

}

function server($addr){

if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}

return $addr;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/184342-php-redirection/
Share on other sites

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.