Jump to content

File Exists (no matter the site)


KingOfHeart

Recommended Posts

I have a decent script for checking if a file exists. However it's not working properly for a guide I uploaded to the same website. So can you help me improve my script, maybe make it looks nicer as well?

 

function urlcheck($flink)
{   
  $link = str_replace(" ","%20",$flink);
  $url_parts = @parse_url( $link );

  if ( empty( $url_parts["host"] ) ) return( false );

  if ( !empty( $url_parts["path"] ) )
    $documentpath = $url_parts["path"];
  else
    $documentpath = "/";

  if ( !empty( $url_parts["query"] ) )
    $documentpath .= "?" . $url_parts["query"];

  $host = $url_parts["host"];
  $port = $url_parts["port"];

  if (empty( $port ) ) $port = "80";
  $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );

  if (!$socket)
    return false;
  else
{
	fwrite ($socket, "GET ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
     
     $http_response = fgets( $socket, 50 );
       
     if ( ereg("200 OK", $http_response, $regs ) )
     {
        fclose( $socket );
			return true;
     } 
	else 
       		return false;
  } 
}

 

http://openzelda.thegaminguniverse.com/guides/KOHTutorial/index.html (says this does not exist) on my openzelda site.

Link to comment
https://forums.phpfreaks.com/topic/198029-file-exists-no-matter-the-site/
Share on other sites

I came up with my own method which seems to solve my problem so far.

 

function urlcheck($flink)
{   
  $link = str_replace(" ","%20",$flink);
  $url_parts = @parse_url( $link );
  
  if(substr($url_parts["path"],2,27)== "openzelda.thegaminguniverse")
  {
$ozfile = substr($url_parts["path"],34);
if(file_exists($ozfile))
	return true;
  }
  


  if ( empty( $url_parts["host"] ) ) return( false );

  if ( !empty( $url_parts["path"] ) )
    $documentpath = $url_parts["path"];
  else
    $documentpath = "/";

  if ( !empty( $url_parts["query"] ) )
    $documentpath .= "?" . $url_parts["query"];

  $host = $url_parts["host"];
  $port = $url_parts["port"];

  if (empty( $port ) ) $port = "80";
  $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );

  if (!$socket)
    return false;
  else
{
	fwrite ($socket, "GET ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
     
     $http_response = fgets( $socket, 50 );
       
     if ( ereg("200 OK", $http_response, $regs ) )
     {
        fclose( $socket );
			return true;
     } 
	else 
       		return false;
  } 
}

 

To me it's simple and I easily understand it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.