Jump to content

Archived

This topic is now archived and is closed to further replies.

m11oct

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

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

Share this post


Link to post
Share on other sites
you might try replacing the '-' with the hex '%' code for it:
[code]$codedhyphen = urlencode('-');[/code]

Share this post


Link to post
Share on other sites
Did you try the HTML entity? –

I get crap sometimes when I don't use entities.  Whatever, just a shot man = )

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.