WebStyles Posted September 9, 2011 Share Posted September 9, 2011 Hi guys. This is my first question on phpFreaks (the other 900+ posts I've made were always an attempt to help someone else) Here's the issue: when using gethostbyaddr($_SERVER['REMOTE_ADDR']) on a local machine (current using MAMP on OS X) the name returned is not the first entry in my /etc/hosts file. (On php.net there's another person also commenting on this and saying that apparently gethostbyaddr selects a random entry from the file.) This is not really an issue, since everything will work fine on my FreeBSD production server where each IP address has only one DNS record (I'm building the company's intranet, so I know exactly what's in our DNS tables) but I'm curious to know if anyone has had the same issue/problem and if there's a way around it. (Logic/Common sense tells me the first record should be the one returned) Currently I have the following information in my /etc/hosts file: 127.0.0.1 localhost 127.0.0.1 iSy 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost # Other names for testing purposes 127.0.0.1 name1.blablabla.com 127.0.0.1 name2.blablabla.com 127.0.0.1 name3.blablabla.com 127.0.0.1 name4.blablabla.com 127.0.0.1 name5.blablabla.com 127.0.0.1 name6.blablabla.com 127.0.0.1 name7.blablabla.com 127.0.0.1 name8.blablabla.com the value returned is always line 8: name2.blablabla.com. If I comment out that line, then it moves 'randomly' to line 12: name6.blablabla.com and sticks with it even if I shut down the servers and then boot up again. any ideas? cheers. Quote Link to comment https://forums.phpfreaks.com/topic/246796-gethostbyaddr-and-etchosts-file/ Share on other sites More sharing options...
AbraCadaver Posted September 9, 2011 Share Posted September 9, 2011 I haven't tested it, but this may work better: 127.0.0.1 localhost iSy name1.blablabla.com name2.blablabla.com #etc... Quote Link to comment https://forums.phpfreaks.com/topic/246796-gethostbyaddr-and-etchosts-file/#findComment-1267416 Share on other sites More sharing options...
WebStyles Posted September 9, 2011 Author Share Posted September 9, 2011 Just tested, the result is the same, it picks a random entry from the line containing the ip address. (this time it's really random, after each refresh it will pick a different name) thanks. Quote Link to comment https://forums.phpfreaks.com/topic/246796-gethostbyaddr-and-etchosts-file/#findComment-1267418 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.