hemi19 Posted September 29, 2009 Share Posted September 29, 2009 Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\examples\htl.php on line 12 Warning: fopen(http://www.google.com) [function.fopen]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\examples\htl.php on line 12 --------------------------------------------------------------------------------------------- actually my code is to get the view source of a web page, but when i enter any url it is displaying the above warning . -----------------------------------------my code is <?php error_reporting (E_ALL ^ E_NOTICE); if(isset($_POST['submit'])) { $domain = $_POST['domain']; //$htmlval=file_get_contents('http://google.com'); echo"name is $domain"; $handle = fopen("http://$domain","r"); //$contents = stream_get_contents($handle); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } //var_dump($contents); } ?></p> <html> <head> <title>HTML Source Code Viewer</title> </head> <body></p> <h2> HTML Source Code Viewer </h2></p> <form method="post" name="pageform" action="htl.php" onsubmit="return validate(this);"></p> <table border="0" style="border-collapse: collapse" width=""> <tr> <td width="" height="91" valign="top"> <table style="border-collapse: collapse" width="" class="tooltop" height="76"></p> <tr> <td> <table border="0" style="border-collapse: collapse" width="" cellspacing="5"> <tr> <td height="28" width="100"><font size="2"><b>View source of</b></font><b><font size="2">: </font></b></td> <td height="28" width=""> <?php echo" <font size=1>http://</font><input type=text name='domain' size='26' value=></td>"; ?> <td height="28" width=""> <input type="submit" name="submit" value="View!" style="float: left"></td> </tr> <tr> <td width="" height="21"> </td> <td width="" colspan="2" height="21" valign="top"><font size="1">(eg. chapagain.com.np)</font></td></p> </tr> </table> </td> </tr> </table> </td> </tr> <?php if(isset($_POST['submit'])) { ?> <tr> <td> <textarea rows="10" cols="60" name="code"><?=$contents?></textarea> </td> </tr> <?php } ?> </table> </form> <script language="JavaScript"> function validate(theform) { if (theform.domain.value == "") { alert("No Domain"); return false; } return true; } </script> </body> </html> ------------------------------------------------------- if anyone knows the problem plz help me out Quote Link to comment Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 Try using file_get_contents() instead of fopen(). Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted September 29, 2009 Share Posted September 29, 2009 hemi9, You might try this PHP function at http://bit.ly/2gtz4g it is a very versatile and robust screen scrapper function written in PHP. It detects and uses cURL if available or uses standard file streams if wrappers are enabled. It will also send proper headers to targets to simulate a valid browser help increase reliability. Quote Link to comment Share on other sites More sharing options...
hemi19 Posted September 29, 2009 Author Share Posted September 29, 2009 for both it is giving same previous errors Quote Link to comment Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 So running this line of code... $htmlval=file_get_contents('http://google.com'); Results in an error for you? Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted September 29, 2009 Share Posted September 29, 2009 If your still getting errors using fopen and file_get_contents then your server may not allow wrappers. Please try the example that I posted above as your server may have cURL enabled. Quote Link to comment Share on other sites More sharing options...
hemi19 Posted September 30, 2009 Author Share Posted September 30, 2009 iam still getting the same error after using ur code. actually iam doing it in localhost Quote Link to comment Share on other sites More sharing options...
corbin Posted September 30, 2009 Share Posted September 30, 2009 Looks like the DNS resolution is failing (as the error blatantly states)..... Do host names resolve out side of a PHP environment? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.