Results 1 to 5 of 5

Thread: warning in fopen()

  1. #1
    Join Date
    Aug 2009
    Posts
    74
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default warning in fopen()

    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

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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?

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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/filesys...llow-url-fopen
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Aug 2009
    Posts
    74
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default

    actually iam getting this error in localhost

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •