Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 m11oct

m11oct
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 09:34 PM

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

#2 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 12 September 2006 - 10:02 PM

you might try replacing the '-' with the hex '%' code for it:
$codedhyphen = urlencode('-');


#3 m11oct

m11oct
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 10:08 PM

I already tried that. It didn't work. I got the same error.

#4 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 12 September 2006 - 11:01 PM

Did you try the HTML entity? –

I get crap sometimes when I don't use entities.  Whatever, just a shot man = )
I'm considered good looking in some countries

#5 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 13 September 2006 - 04:03 PM

did you try adding just 'http://' to the beginning of the url?

#6 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 13 September 2006 - 04:38 PM

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?

#7 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 13 September 2006 - 05:34 PM

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 dns-get-record() 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 curl() or fsockopen.

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users