Feed on Posts or Comments

Personal Daantje on 20 Dec 2006 12:32 am

linkValidator

I’ve GPLed an old class of mine. This PHP class, a link validator, I wrote in october 2003 and only used it in a site of mine nlweed.com (I’ve sold it.) to check if posted links are still valid. Now I found the class and thought that it would be a waste only to use it ones. This class can check a link and will return the status. Easy to implement in your own scripts. So here is the GPLed version. Check the source for documentation and the readme for code examples.

FEATURES:

Here are the features of the current version 0.3:

  • Follows redirection headers when status is an 300, 301, 302 till 399.
  • Checks with the HTTP/1.0 and/or HTTP/1.1. protocol.
  • Doesn’t use any system or command line tools.
  • Easy to implement.
  • PHP4 and PHP5 compatible.

TODO:

When somebody feels the need to help developing this project…

HISTORY:

Here are the changes made to this class:

  • version 0.3:
    (Sun Mar 23 01:18:04 CEST 2008)

    • The class follows redirects when status is between 300 and 399…
      Default this option is set TRUE!! This can be disabled as shown
      in example 4 in this file, with the follow_redirects().
      Thanx to Felix Nagel for the feature request.

    • Also tested and works on PHP4 and PHP5.
    • Fixed PHP warnings.
  • version 0.2:
    (Mon Mar 28 15:45:54 CEST 2005)

    • Now the class tries the HTTP/1.0 protocol first and than when a 400 status is given, tries the HTTP/1.1. This will fix hanging on some old servers. Thanx to __DireWolf for the bug report.

LICENSE:

GPL (http://www.gnu.org/licenses/gpl.txt)

SUPPORT:

Please report any bugs to me at daantje dot nl

DONATE:

Please support this project by paypal donations, (my email is my paypal address)

Help me develop this and other projects. Donate to the good cause.
donation button

DOWNLOAD:

Download and untar the file (tar -zxvf linkValidator.tgz), upload it and point your browser to one of the examples. Windows users can use WinRAR to decompress the file.

EXAMPLE

There is an example included in the package. Mind that you can only check url’s on my domain. This because of my firewall settings. These will work: http://www.daantje.nl/index.php or http://www.daantje.nl/projects/linkValidator/test.php

linkValidator

by: daantje.nl

url:

I need one argument, a URL would be nice…

DOCUMENTATION

You should check your firewall, the class opens an outgoing tcp port 80. For more info and code examples read the README.txt.
Here’s the syntax ref.:

  • BOOL $status = linkValidator::linkValidator( [STRING $url] [, STRING $referer] )

    Does it all at ones… When referer is empty, it will be calculated from given url….
    When all arguments are empty, the constructor will do nothing.

  • ASSOC_ARRAY $array = linkValidator::disectURL( STRING $url )

    Will disect an URL and will return it in an associative array.
    Available keys will be ‘host’, ‘port’ and ‘get’

  • STRING $string = linkValidator::open(STRING $host, INT $port, STRING $get,
    STRING $referer [, STRING $protocol])

    Open a connection, check the $get URI and return the status…
    Returns ‘Connection refused.’ on no status found, or host down.
    Optional protocol can be 1.0 or 1.1. Default it will check 1.0 and when that fails it will try 1.1 automaticly.

  • BOOL $works = linkValidator::status()

    Will return ‘true’ when the last link gave a status below 400.
    Else it will return ‘false’.

  • STRING $string = linkValidator::message()

    returns the complete status message of the last link.

  • VOID linkValidator::follow_redirects( BOOL $follow_redirects )

    By default this option is set TRUE. You can use this method to disable it.

4 Responses to “linkValidator”

  1. on 24 Jan 2008 at 7:14 pm 1.SEO Consultant said …

    Thanx u a lot. I am a SEO & PHP Developer myself.. I am going to implement it in my site and check.

  2. on 15 Sep 2008 at 9:45 pm 2.Tim said …

    Does not validate correctly if is https.

  3. on 15 Sep 2008 at 9:53 pm 3.Daantje said …

    If somebody knows on how to implement ssl in the class with _NATIVE_ php and _NO_ system or exec calls, I would be verry happy. Until then the class can not validate secure links with https. Sorry.

  4. on 15 Sep 2008 at 10:05 pm 4.Daantje said …

    Found it: http://nl.php.net/manual/en/book.openssl.php
    So it can be done ;) When you have the right modules installed/compiled into PHP… I don’t have the need to implement it my self. I do not need to validate secure links my self. And I now just don’t have the time to do the coding for free. May be at a later time :)

Trackback | Comments RSS Feed

Leave a Reply

You must be logged in to post a comment.