<script language="javascript">
function checkinput()
{
alert ("inside javascript");
if ((document.getElementById("sitename").value=="")){
document.getElementById("pgcmptext2").value="Please Enter a domain name";
document.getElementById("sitename").focus();
alert ("invalid");
}
else
{
document.htmlviewform.submit();
alert ("valid");
}
}
</script>
<?php
$disp=0;
if (isset($POST['sitename']))
{
$temp=$POST['sitename'];
$handle = fopen($temp,"rb");
if ($handle==true)
{
$disp=3;
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
$result .= htmlentities($buffer);
}
fclose($handle);
}
else
{
$result="Unable to access domain.Please verify address and try again";
}
}
?>
<form method="post" action="" name="htmlviewform" >
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="25%"><div class="textstylename1">Enter domain name:</div></td>
<td width="1%"></td>
<td width="62%"><input name="sitename" id="sitename" type="text" maxlength="300" size="50" value="<?php if (isset($POST['sitename'])) echo ($POST['sitename']) ?>"/></td>
<td width="12%"><input type="button" value="submit" name="subm" onclick="checkinput()"></td></tr><tr><td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"><div align="center"><textarea id="pgcmptext2" readonly="readonly" name="htmltxt"><?php echo $result;?></textarea></div></td>
<tr>
</table>
</form>
this is the complete code which i have written for viewing the html source code of a form.this
works fine for blank values/valid values entered in the site name.
The problem is here :If i enter an invalid address
like
"http://www."
"http://www.abc.du" etc ,then the textarea displays this error message:
"Unable to access domain.Please verify address and try again"(which is fine).
The problem is that along with this i get the following error too.
"Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home2/king/engine-www/tools/html-code.php on line 247
Warning: fopen(http://www.abc.du) [function.fopen]: failed to open stream: No such file or directory in /home2/king/engine-www/tools/html-code.php on line 247"
note : Line 247 is "fopen".how do i rectify the above error.pls help.
once again how do i change fopen for invalid URL's