Page/Link Validatioin

Posted on 2007-10-15
Last Modified: 2008-03-22
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 = "";
            $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";
Question by:mopar003
    LVL 17

    Accepted 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
    LVL 20

    Expert Comment

    $host = '';
    if($socket = fsockopen($host, 404, $errno, $errstr, 30)) {
    echo 'up!';
    } else {
    echo 'down.';
    LVL 1

    Author Comment

    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?
    LVL 20

    Expert Comment

    for more info read
    LVL 20

    Expert Comment

    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.
    LVL 20

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now