Checking a url exists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mindwarp

    Checking a url exists

    Hi,

    I've looked on this newsgroup on google and on php.net, but I can find
    a work function which will allow me to check if a url exists?

    Can anyone provide me with one?
    or point we towards one?

    Best regards,

    Jules.

  • ImOk

    #2
    Re: Checking a url exists

    I dont have code for this but you can do it fairly easily with sockets.
    (see php docs)

    1) create a socket resource
    2) connect to the socket on port 80
    3) send the URL
    4) read the response.

    Check for errors on each of the steps above


    mindwarp wrote:
    Hi,
    >
    I've looked on this newsgroup on google and on php.net, but I can find
    a work function which will allow me to check if a url exists?
    >
    Can anyone provide me with one?
    or point we towards one?
    >
    Best regards,
    >
    Jules.

    Comment

    • mindwarp

      #3
      Re: Checking a url exists

      Hi,

      I've had a few attempts and always come up with a 200 return code.
      I guess 404 handling pages are causing this.


      Jules.

      Comment

      • mindwarp

        #4
        Re: Checking a url exists

        For example...

        <?php

        $url = 'http://www.whatever.co m/ccc';

        $fp = @fopen($url, 'r');

        if ($fp) {

        $headers = stream_get_meta _data($fp);

        print_r($header s);


        }

        Comment

        • Krustov

          #5
          Re: Checking a url exists

          <comp.lang.ph p>
          <mindwarp>
          <12 Jul 2006 08:46:15 -0700>
          <1152719175.282 661.259750@35g2 000cwc.googlegr oups.com>
          I've looked on this newsgroup on google and on php.net, but I can find
          a work function which will allow me to check if a url exists?
          >
          Can anyone provide me with one?
          or point we towards one?
          >
          $skunk="http://www.emailuser.c o.uk";
          if (fopen($skunk,' r')===FALSE) {exit;}

          Although it doesnt work if the website uses a custom 404 webpage and i
          never got around to doing any more work on it .


          --
          Encrypted email address

          Comment

          • mindwarp

            #6
            Re: Checking a url exists

            hi,

            yes, i want to cater for custom 404 pages

            :(

            Jules.

            Comment

            Working...