SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there any error in PHP or I am missing something?

    Hi!

    Is there any error in PHP or I am missing something?
    I am trying to see whether the URL Exists or not by using this,
    PHP Code:
    if(file_exists('http://www.abc.com/xyz.html'))
    echo 
    "Yes, it Exists";
    else
    echo 
    "Not exists"
    I am always getting Not exists, in the output, whether file exists or not.
    Why I am not getting Yes, it Exists, if the file exists in actual.

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi I got the method.
    Thanks.

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mohansinfh View Post
    Hi I got the method.
    Thanks.
    Please, share your findings. Otherwise this is an entirely wasted page, clogging up the intertubes with no useful information at all. (But congrats on finding a solution yourself.)
    Salathe
    Software Developer and PHP Manual Author.

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure,

    This is the method,

    PHP Code:
    $ch curl_init("http://www.abc.com/xyz.html");

    curl_setopt($chCURLOPT_NOBODYtrue);
    curl_exec($ch);
    $retcode curl_getinfo($chCURLINFO_HTTP_CODE);
    // $retcode > 400 -> not found, $retcode = 200, found.
    curl_close($ch);

    if(
    $retcode == 200)
    {
    echo 
    "Found";
    }
    elseif(
    $retcode == 400)
    {
    echo 
    "Error";



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
  •