m11oct Posted September 12, 2006 Share Posted September 12, 2006 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 105Warning: fopen(--): failed to open stream: Permission denied in ---.php on line 105Is there a workaround for this?Thanks Quote Link to comment Share on other sites More sharing options...
mainewoods Posted September 12, 2006 Share Posted September 12, 2006 you might try replacing the '-' with the hex '%' code for it:[code]$codedhyphen = urlencode('-');[/code] Quote Link to comment Share on other sites More sharing options...
m11oct Posted September 12, 2006 Author Share Posted September 12, 2006 I already tried that. It didn't work. I got the same error. Quote Link to comment Share on other sites More sharing options...
gijew Posted September 12, 2006 Share Posted September 12, 2006 Did you try the HTML entity? –I get crap sometimes when I don't use entities. Whatever, just a shot man = ) Quote Link to comment Share on other sites More sharing options...
mainewoods Posted September 13, 2006 Share Posted September 13, 2006 did you try adding just 'http://' to the beginning of the url? Quote Link to comment Share on other sites More sharing options...
shoz Posted September 13, 2006 Share Posted September 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
shoz Posted September 13, 2006 Share Posted September 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.