PDA

View Full Version : warning in fopen()



hemi
09-29-2009, 10:12 AM
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">&nbsp;</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

bluewalrus
09-30-2009, 04:37 AM
I don't know about wamp (I have mamp sounds similiar right) but do you have it turned on and are able to open other pages?

djr33
09-30-2009, 06:25 AM
For including an external site, you must enable loading external domains in your configuration. If your code works for local pages but not external pages, then this may be the problem.


From the page for include(), a similar function:
"Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled."

See info on that here:
http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

hemi
09-30-2009, 09:24 AM
actually iam getting this error in localhost

djr33
10-01-2009, 05:39 AM
You are getting this when running it on localhost, or when including a page from localhost? If you can't even get local pages, then I'm not sure. I'd say take apart your code to make it as simple as possible and see if you can reduce it to one line that isn't working. From there it shouldn't be too hard to fix.