nikosb Posted November 25, 2006 Share Posted November 25, 2006 I have problems reading the contents of certain urls and I am very puzzled as to the reason I can not do it succesfully.I have the following PHP code:[code]<?phpWebsite:<FORM ACTION='readpage.php'><INPUT TYPE='text' NAME='site' VALUE="http://f650.com/phpBB2/" SIZE=80><INPUT TYPE='submit' NAME='SEND'><BR>Read webpage using:<INPUT TYPE='radio' NAME='radio' VALUE='method1'>fopen<INPUT TYPE='radio' NAME='radio' VALUE='method2'>HTTP-request<INPUT TYPE='radio' NAME='radio' VALUE='method3' checked>CURL</FORM><?phpif(isset($_GET['site'])){ $site = $_GET['site'];}else{ $site = "http://f650.com/phpBB2/";}//Read contents of webpage using fopen function.if($_GET['radio']=='method1'){ $file = fopen ($site, 'r') or die($php_errormsg); if (!$file) { echo "<p>Unable to open remote file.\n"; exit; } else { while (!feof ($file)) { $line = fgets ($file, 1024); $page .= $line; } fclose($file); }}//Read contents of webpage using HTTP-Request method.if($_GET['radio']=='method2'){ require 'HTTP/Request.php'; $r = new HTTP_Request($site); $r->sendRequest(); $page = $r->getResponseBody();}//Read contents of webpage using the CURL method.if($_GET['radio']=='method3'){ $c = curl_init($site); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec($c); curl_close($c);}echo $page;?>[/code]The function of this code is to read the contents of the url provided by the user. The user can also select the method (fopen, HTTP-Request, or CURL) with which to read the url. I posted the code athttp://www.eng.umd.edu/enme331/readpage.php for you to try. Here are two good examples:Example 1.So when reading a particular website (f650.com/phpBB2/) the relative links are not correct. For example the relative link to "General Discussion" forum should be"viewforum.php?f=8"However when I read the file with the program the relative link changes to:"viewforum.php?f=8&sid=72b8381c30fdfdeb6e1cd8a51abed1ef"Why does the program read different the contents of the url? What is also more confusing is that when I use a different method to read the same url the relative link is not only wrong but it is also different. For example I get a different relative link with CURL than with FOPEN or HTTP_REQUEST. Any ideas what is wrong here?Example 2When reading the contents of another forum (just type http://www.zend.com/forums/index.php?t=thread&frm_id=11& amp;S=5def8a6aed7aca4169a2925e00a30e5a in the website input) I also get the same strange behavior. The relative link to one of the threads named "Hi anyone can help me?" isindex.php?t=msg&th=2424&start=0&S=5def8a6aed7aca 4169a2925e00a30e5aThe php program read a different relative link:index.php?t=msg&th=2424&start=0&S=6e1ed0488ac1a7 2744e5820fa2e6bb9f I have looked at my code a lot of times and I don't see anything obvious that would create this strange behavior. What am I missing?Thank you,Nikolaos Link to comment https://forums.phpfreaks.com/topic/28392-read-url-inconsistency/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.