Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

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?

            $myURL = "http://www.google.com";
            $fileURL = $myURL;
            $read = fopen($fileURL, "r") or die();
            $value = "";
            while(!feof($read)){ $value .= fread($read, 10000); }
            //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";
  • 4
1 Solution

if ($DEBUGTEST==1) echo count($links)." links in input<BR>";
// inits
// loop through $links[] (beforehand filled in by you)
for ($i=1;$i<=count($links);$i++) {
// try to access that link
if ($DEBUGTEST==1) echo "link $i '".$links[$i]."' is ".(($isgood)?'OK':'KO')."<BR>";
// memorize result
if (! $isgood) $bad[]=$i;
// display bad links
if ($DEBUGTEST==1) echo "$badlinks bad links found<BR>";
for ($i=0;$i<$badlinks;$i++) echo "bad link '".$links[$bad[$i]]."' (index=$i)<BR>";
// done

function CheckURI($parurl) {
// inits
// try to get URI
$filename = "$parurl";
$fd = @fopen ($filename, "r");
if ($fd) { // si page trouvie
  while ((!feof ($fd))and($tobec)) {
    $ligne= fgets($fd, 4096);
    if (!(strpos($ligne,'[404] Not Found')===false)) $tobec=FALSE; // stop as soon as this is encountered
    $contents []=$ligne;
  } // while lecture bloquante
  fclose ($fd);
  if ($tobec) { // file entirely read OK (note that we could stop after X first lines, the '404' message is not at the 345th line...
    // nothing, result is TRUE already
    // this block is in case you want to log anything like "last correct date where found the URI was OK"
  } else { // we stopped before the end : 404 found
} else { // page not found
} // if page trouve ou non
return $result;
} // CheckURI Boolean Function
$host = 'http://google.ae';
if($socket = fsockopen($host, 404, $errno, $errstr, 30)) {
echo 'up!';
} else {
echo 'down.';
mopar003Author Commented:
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?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

for more info read
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.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now