jigen7 Posted September 13, 2007 Share Posted September 13, 2007 i have here a function that accept a string and url site so that it will search a certain keywords if it is included or mention at a given url but some time fopen cant open a couple of sites, what i need is to have a error trapping so that if fclose cant open that site it will jsut skip the url given and return null?? im having trouble because i need the the variable where the site is so that i can use it in searching all of it line for the string given.. function search_all($url,$search_criteria){ $size = 0; $the_page = fopen($url, "r"); //i think here is the line where i should edit while(!feof($the_page)) { $each_line = fgetss($the_page, 255); //echo "$each_line <br>"; if(eregi($search_criteria, $each_line, $results)) { // for each line where there is a match, increment a counter $size++; } } fclose($the_page); //print("I found $size ocurrences of $search_criteria at $url"); return $size; } Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/ Share on other sites More sharing options...
Fadion Posted September 13, 2007 Share Posted September 13, 2007 fopen() returns false if the open process fails, but probably that's not your case. Why fopen() cant open specific sites? If it reads some sites, it should read them all. Are u having an error while trying to fopen() those sites? Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347478 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 yes sometimes it gives error that it cant open the site pass url so my script gives error but when i tried to open the url it eventually open so i just need to check if ever the fopen cant open the site then i jsut have to return some value eventually Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347483 Share on other sites More sharing options...
marcus Posted September 13, 2007 Share Posted September 13, 2007 Is it readable? Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347484 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 heres the error Warning: fopen(http://www.yardbyyardfabricsandcrafts.com/store/LDpage.asp?CategoryID=8&Category_Name=Online+Shopping) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 403 Access Denied in E:\wwwroot\htdocs\jigen\google_search\function.php on line 55 so how can i trap that error so that i just have to skip checking its content if it cant open that i also check that the url (http://www.yardbyyardfabricsandcrafts.com/store/LDpage.asp?CategoryID=8&Category_Name=Online+Shopping) is accesable how come it gives me that error Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347490 Share on other sites More sharing options...
marcus Posted September 13, 2007 Share Posted September 13, 2007 If the folder is protected you'll have no access. Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347496 Share on other sites More sharing options...
Fadion Posted September 13, 2007 Share Posted September 13, 2007 Probably its read. To bypass the error try: $handle = @fopen('page.php', 'r'); if(!$handle){ return NULL; } //rest of the function's code Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347507 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 what is the @ sign for?? Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347514 Share on other sites More sharing options...
Fadion Posted September 13, 2007 Share Posted September 13, 2007 To surpress the error message from showing. The code does custom error handling so there's no need for error messages. Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347518 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 ok it works so some site is protected so it cant be fopen right???so is there a way to bypass the protection? Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347527 Share on other sites More sharing options...
Fadion Posted September 13, 2007 Share Posted September 13, 2007 from a google search i found that to fix these http streams errors u need to update to the latest version of php5 or recompile php4 with larger FD_SETSIZE. If u are on php4 with FD_SETSIZE 1024 on a shared host, i guess theres nothing to do other then wait for them to upgrade to version 5. Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347533 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 Here our phpinfo so it is not updated enough o well ill just try to ask if it can be updated so that the fopen can be use properly System Windows NT GOLDMINE 5.2 build 3790 Build Date Nov 2 2006 11:50:55 Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" Server API Apache 2.0 Handler Virtual Directory Support enabled Configuration File (php.ini) Path C:\WINDOWS\php.ini PHP API 20041225 PHP Extension 20060613 Zend Extension 220060519 Debug Build no Thread Safety enabled Zend Memory Manager enabled IPv6 Support enabled Registered PHP Streams php, file, data, http, ftp, compress.zlib Registered Stream Socket Transports tcp, udp Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.* Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347536 Share on other sites More sharing options...
jigen7 Posted September 13, 2007 Author Share Posted September 13, 2007 thx for everyone helping me in my prob i got the proper coding by using curl library i was able to create another function that checks the url for a certain ketwoord here the final function function search_call($url,$search_criteria){ $size = 0; $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL, and return output $output = curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); if (eregi($search_criteria, $output)) { $size = 1; } return $size; } Link to comment https://forums.phpfreaks.com/topic/69123-solved-help-fopen-problem/#findComment-347566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.