Jump to content
  • Advertisement
Sign in to follow this  

[web] check for 404 in php

This topic is 3907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

No. When you're in a script it means by definition that it has been found. Of course, you can emit a 404 inside a php script with the header() command.

What you can do is have Apache load a php file when it detects a 404. E.g:

ErrorDocument 404 /404.php

Most webhosts allow you to specify custom error documents using the control panel.

Share this post

Link to post
Share on other sites
However, if you mean checking the status of an external url, you can do this with the cURL extension.

$url = 'http://urltocheck';

$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_NOBODY, 1);
curl_setopt($c, CURLOPT_HEADER, 1);
$link_headers = curl_exec($c);
$info = curl_getinfo($c);

// $info['http_code'] should contain the response code of $url

Additionally, $link_headers will have all the headers of $url in it.

Hope this helps, if thats what you were looking for.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!