php - Show message if header location redirect fails -


this question has answer here:

i need redirect unknown address. if address not available show message user. how that?

<?php header("location: http://www.example.com/");  exit; ?> 

the direct method retrieve page:

if (file_get_contents('http://www.example.com/') !== false) {   header("location: http://www.example.com/");    exit; } 

http://php.net/manual/en/function.file-get-contents.php

however, tells if available @ page. won't tell if, instance, you got 404 error page instead.

for (and save memory cost of downloading whole page), can get_headers() url instead:

$url = "http://www.example.com/"; $headers = get_headers($url); if (strpos($headers[0],'200 ok') !== false) { // or   header("location: ".$url);    exit; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -