Link to home
Start Free TrialLog in
Avatar of mopar003
mopar003

asked on

Page/Link Validatioin

Anyone have a way to validate a link prior to execution?  Heres the code I have, but if the server is down fopen errors out.  Any other ideas?

//CHECK THE STATUS OF THE PAGE
            $myURL = "http://www.google.com";
            $fileURL = $myURL;
            $read = fopen($fileURL, "r") or die();
            $value = "";
            while(!feof($read)){ $value .= fread($read, 10000); }
            fclose($read);
            //GET CONTENT OF PAGE
            if(strpos($value, "<TITLE>Sign On</TITLE>") > 0) {
                  echo "Page is live, go on to it";
            } else {
                  echo "Page is missing, show message";
            }
ASKER CERTIFIED SOLUTION
Avatar of nplib
nplib
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<?php
$host = 'http://google.ae';
if($socket = fsockopen($host, 404, $errno, $errstr, 30)) {
echo 'up!';
fclose($socket);
} else {
echo 'down.';
}
?>
Avatar of mopar003
mopar003

ASKER

This works to some extent, but what ere the variable #errno, and $errstr passing?   Also, It always fails right now.  Is there an issue with checking an https:// URL?
https may be an issue
HTTPS stands for Hypertext Transfer Protocol over Secure Socket Layer, or HTTP over SSL.

HTTPS encrypts and decrypts the page requests and page information between the client browser and the web server using a secure Socket Layer (SSL). HTTPS by default uses port 443 as opposed to the standard HTTP port of 80. URL's beginning with HTTPS indicate that the connection between client and browser is encrypted using SSL.

SSL transactions are negotiated by means of a keybased encryption algorithm between the client and the server, this key is usually either 40 or 128 bits in strength (the higher the number of bits the more secure the transaction).

HTTPS should not be confused with S-HTTP, a security-enhanced version of HTTP. SSL and S-HTTP have very different designs and goals so it is possible to use the two protocols together. Whereas SSL is designed to establish a secure connection between two computers, S-HTTP is designed to send individual messages securely.

Both protocols have been submitted to the Internet Engineering Task Force (IETF) for approval as a standard.