How to check url exist or not on server

Discussion in 'PHP' started by dineshsingh1984, Jul 4, 2011.

  1. #1
    how to check url exist or not server

    I try with following code but this is not properly working

    <?php
     
    $url = "http://www.exampless.com";
    $headers = @get_headers($url);
    if(strpos($headers[0],'404') === false)
    {
      echo "URL Exists";
    }
    else
    {
      echo "URL Not Exists";
    }
    ?>
    PHP:
    so plz give the script for checking url exist or not.............
     
    Last edited: Jul 4, 2011
    dineshsingh1984, Jul 4, 2011 IP
  2. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What do you mean by 'properly not working'?
    I just tried , it worked wonder!
     
    eleetgeek, Jul 7, 2011 IP
  3. elixiusx

    elixiusx Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    The problem is some sites don't send the code 404, they send the code 200 and show you a dynamic 404 page.

    Try this:
    
    <?php
    #$url = 'http://www.amazon.com/amazon.asdasd'; # Not Exists
    $url = 'http://www.amazon.com/books-used-books-textbooks/b/ref=sa_menu_bo8?ie=UTF8&node=283155'; // Exists
    
    # This strings depends of the language and depends of the site, but the common are:
    $strings = array('404 Not found', '404 - Document Not Found');
    
    $info = @file_get_contents($url);
    
    if(!$info)
    	print 'URL Not Exists';
    else 
    {
    	$exists = true;
    	foreach( $strings as $string  )
    	{
    		if( eregi($string, $info)  )
    			$exists = false;
    	}
    	
    	if( !$exists )
    		print 'URL Not Exists';
    	else print 'URL Exists';
    }
    ?>
    
    PHP:
     
    elixiusx, Jul 7, 2011 IP
  4. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    I mean if any site or domain are available for example :http://youngangels.in and one incorrect domain for example : http://youngang_els.in which are not correct then his script show the both url valid whenever http://youngang_els.in are not correct but script show this is valid.....

    how can solve this problem ??????????



     
    dineshsingh1984, Jul 7, 2011 IP
  5. yusuyi

    yusuyi Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    using fsockopen to get the page info and then check the first line
    such as HTTP/1.1 302 Found
     
    yusuyi, Jul 9, 2011 IP