How do I check if a URL is exists in PHP, without following redirects? -
i have php script call notfound.php
executed when web site hits 404, , try create valid url based on logic have written. after create new url check if thats valid url or not.to have tried get_headers
, curl
, , file_get_contents
. file_get_contents
return valid answer. problem i'm facing right if new url 404, file_get_contents
again go in notfound.php
, , take ages new url 404. think going on loop or something.
then tried send $context
file_get_contents
saying follow_location = 0
, didnt work either.
i spend whole day looking answers failed :(, 1 got ideas?
i don't know why want show valid content if there none. bad seo, in opinion.
so best case send headers (404/500 etc) on not found page.
on page self show user message. url not exists, recommend following urls (give couple of urls user can choose (always show homepage)).
but if want stick design chould set variable ?no-lookup=true. if hits 404 page wont end in loop. if no throw 404 header , use curl header info , see if 404 page
Comments
Post a Comment