Jump to content

PHP Call Home


calvin182
 Share

Recommended Posts

What I'm looking to do is check a file from my site for a specific varible containing current version info for a script i wrote. If the file can be reached yippie, but if it cannot i dont want some uguly error craping up the place, i'd like a nice 'server cannot be reached at the moment' message or something like it. The file to be reached is just a simple .txt or .php text file only containing the variable... any thoughts on how to do this anyone?

Link to comment
Share on other sites

Take a look at this:http://www.php.net/manual/en/function.http-get.phpYou might be able to do something like this:

$response = http_parse_message(http_get($url));

$response->responseCode will hold (oddly enough) the response code, which will be 200 for OK or 404 for not found, among others. $response->body will hold the body of the response (the text of the file).

Link to comment
Share on other sites

Including a file would only be equivalent to the string "OK" if you have a return statement in the include file that returns the string "OK". It's probably better to check for false:if ((include 'http://....') !== false)But that will also return false if the URL wrappers for include are not enabled, regardless of whether the server is online or not.Also:

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...