KingOfHeart Posted April 8, 2010 Share Posted April 8, 2010 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 More sharing options...
KingOfHeart Posted April 11, 2010 Author Share Posted April 11, 2010 Too tough? Did I leave out some type of detail? Link to comment https://forums.phpfreaks.com/topic/198029-file-exists-no-matter-the-site/#findComment-1039836 Share on other sites More sharing options...
dreamwest Posted April 11, 2010 Share Posted April 11, 2010 Why are you parsing the url to begin with? This is the wrong approach - use curl instead http://www.wizecho.com/nav=scripts&s=spider Link to comment https://forums.phpfreaks.com/topic/198029-file-exists-no-matter-the-site/#findComment-1039873 Share on other sites More sharing options...
KingOfHeart Posted April 11, 2010 Author Share Posted April 11, 2010 Anything more simplified? I don't see the point of complicating things just to see if a file exists. Link to comment https://forums.phpfreaks.com/topic/198029-file-exists-no-matter-the-site/#findComment-1040083 Share on other sites More sharing options...
KingOfHeart Posted April 11, 2010 Author Share Posted April 11, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198029-file-exists-no-matter-the-site/#findComment-1040106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.