SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A function to check if a URL actually exists??

    Hi All

    I would like to know if there is someway of taking a url submitted in a form and check for its actual existance before saving it in my DB. Does PHP have any kind of functions or classes that check the existance of a URL, returning true or false accordingly.

    Regards, Ben

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    London, England
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able using fopen like
    PHP Code:
    $url 'http://www.whatever.com/';
    if ( 
    $fp fopen ($url'r') ) {
        
    //  exists
    } else {
        
    // dont exist


  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2 things.

    1. You're example WILL work, however;
    1.1: If it does NOT work, then it'll spit out fopen errors, you can fix this by using the @ symbol
    1.2: You don't need the "$fp = " part:

    PHP Code:
    $url 'http://www.whatever.com/'
    if (
    fopen ($url'r')) { 
        
    //  exists 
    } else { 
        
    // dont exist 


    2. You can use this too:

    http://www.spoono.com/tutorials/php/validurl/

    2.1: I don't quite understand the function, but it works..

    2.2: The first one makes more seanse, I'd use it.


    Hope I helped!

    Thanks,
    ~someonewhois


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •