homepage Welcome to WebmasterWorld Guest from 54.205.242.179
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Get domain from gethostbyaddr?
norbiu




msg:3953709
 2:30 pm on Jul 16, 2009 (gmt 0)

IP: 100.100.100.100
Hostname: 100-100-100-100.verizon.net

How do I extract the domain from the host name?

 

norbiu




msg:3953717
 2:43 pm on Jul 16, 2009 (gmt 0)

Found a solution:

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

$string = $hostname;
preg_match('@^(?:http://)?([^/]+)@i', $string, $matches);
$host = $matches[1];
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "Domain: " . $matches[0] . "\n";

Well, at least it will get indexed by Google! :)

NomikOS




msg:3955181
 2:25 am on Jul 19, 2009 (gmt 0)

i don't sure, but there seems to be some errors:
escaping some dots . and slashes /
and matching $matches[1]
$string = $hostname; 
preg_match('@^(?:http://)?([^\/]+)@i', $string, $matches);
$host = $matches[1];
preg_match('/[^\.]+\.[^\.]+$/', $host, $matches);
echo "Domain: " . $matches[1] . "\n";

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved