mythsmx Posted December 8, 2009 Share Posted December 8, 2009 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184342-php-redirection/ Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Try moving the server() function up, so it's above the function call. PHP has to know about the function before it can call it. Quote Link to comment https://forums.phpfreaks.com/topic/184342-php-redirection/#findComment-973533 Share on other sites More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 PHP has to know about the function before it can call it. Ummm no it doesn't. You can define a function anywhere on the page and PHP can call that function just fine anywhere on the page. Functions are put into memory before the script is ran. Quote Link to comment https://forums.phpfreaks.com/topic/184342-php-redirection/#findComment-973552 Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Doh. Getting my PHP and Javascript mixed up. Quote Link to comment https://forums.phpfreaks.com/topic/184342-php-redirection/#findComment-973575 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.