Patrick Troust Patrick Troust - 23 days ago 16
PHP Question

Redirect to another page if stream is offline (PHP)

$fp = fsockopen("www.example.com", 8000, $errno, $errstr, 1); //last param is timeout in seconds
if (!$fp) {
header('Location: http://www.anothersite.com/some_message');
} else {
fclose($fp); // radio OK
}


The code is not working and do not redirect.

Answer
ob_start();
//something
ob_end_clean(); //erase output
header('Location: ');
Comments