Check If Web Page Ok Before Redirecting?
How do I create a php file 'redirect.php' That takes 1 input parameter 'URL', have to check the URL Page is not dead before rediecting? Example 1 user clicks on link http://domain
Solution 1:
You can use CURL to access the web page in code, and see if you get a valid result.
However, I am not seeing any benefit to doing this. Either it's down and they get your 'not in service' message, or it's down and they get the browser message that it's down... In the process, you've doubled the traffic from your site to the target site unnecessarily.
Solution 2:
Use curl or something to grab the headers of the redirect and check for the 200 message. That's an "OK" from the webserver.
You should use the CURLOPT_HEADER
option to echo out the options.
Solution 3:
Try this:
<?phpif (fopen($_GET['url'], "r")) {
header('Location: ' . $url);
}
else {
// Say it is not OK
}
?>
Post a Comment for "Check If Web Page Ok Before Redirecting?"