Jump to content

fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known


m11oct

Recommended Posts

Hello,

I've experienced a problem trying to access URLs which have a hyphen in certain areas of the URL. The URL is constructed like this: "something-.example.com" where the hyphen is immediately before the .example.com bit.

The error received is:

Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in ---.php on line 105

Warning: fopen(--): failed to open stream: Permission denied in ---.php on line 105

Is there a workaround for this?

Thanks
Link to comment
Share on other sites

It's my understanding that a - isn't allowed to be in the hostname at that location. I've also tried opening sites that claim to have similar hostnames and I haven't had success resolving one in firefox.

You're able to open a sample page with a hostname in that format?
Link to comment
Share on other sites

I've been able to use the "host" app to do the dns lookup of a sample host with the "-" in that location, but telnet/firefox/opera also issue an error.

They all send the UDP request to the DNS server and all receive a reply, but the apps mentioned prematurely give an error. I have to assume that because the apps know what a valid hostname looks like they issue an error because it's "invalid"

I've been able to telnet using the ip address returned from "host" and using the "hostname" in the value for the "Host: " header, retrieve the page needed.

I'm running this from linux. It's possible that all the apps are using the same library and function to do the lookup and it is that function that returns an error. Meaning that all apps are unable to access the specified sites.

If you're using PHP5 the function [url=http://www.php.net/dns_get_record]dns-get-record()[/url] is able to retrieve the information needed (ie the ip address). From the look of the example output in the manual, you could loop through the array until you find the "ip" key set and use that ip address to connect to using perhaps [url=http://www.php.net/curl]curl()[/url] or [url=http://www.php.net/fsockope]fsockopen[/url].

You'd then use curl to add the "Host:" header with the specified hostname or use fwrite to send the Host: header after connecting with fsockopen.

There may be another way, but those are the ones that come to mind.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.