|
|
|
HEY YOU!!!,
Our records indicate that you have never posted to our site before! Why not make your first post today by saying hello to our community in our new people forums.
To access all the good good stuff you need to post, post, and post more.
|
05-25-2004, 07:36 AM
|
#1
|
|
whore
Join Date: Jan 2004
Location: 2nd biggest state
Posts: 27/0.02
Threads: 0
|
PHP help
I'm look for a way to stip down IP's and hostnames to display them on a web page. I can display them no problem, but I looking to replace some of the octets with *, instead of numbers. Ie 10.1.3.x. For the hostname part, I'm looking to only display the network they are from, not dialupuser.23.level4.net, I would only like to display level4.net. I have figured out of most of this, but I am running into issues with people that come from au.com or co.nz or com.my networks because of the why the code works it only displays the last two segments of the hostname, not sure if I can make it "smart" or not.
PHP Code:
<?php
$Host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
print $Host;
print "<br>";
preg_match("/[^\.\/]+\.[^\.\/]+$/", $Host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
Any thoughts?
|
|
|
|
|
|
|
quote
|
|
05-25-2004, 03:24 PM
|
#2
|
|
whore
Join Date: Jan 2004
Location: 2nd biggest state
Posts: 27/0.02
Threads: 0
|
Re: PHP help
In case anybody wanteds the IP code..here it is...just change the $octs[x] to x out the octet you want to hide.
PHP Code:
<?php
// 0 is 1st, 1 is 2nd, 2 is 3rd, and 3 is 4th
$ip = $_SERVER['REMOTE_ADDR'];
$octs = split('\.', $ip);
$octs[3] = ereg_replace("[0-9]", "x", $octs[3]);
//$octs[2] = ereg_replace("[0-9]", "x", $octs[2]);
$hideem= join(".", $octs);
print $hideem;
?>
|
|
|
|
|
|
|
quote
|
|
06-01-2004, 11:35 AM
|
#3
|
|
whore
Join Date: Jun 2004
Location: SoCal
Posts: 364/0.22
Threads: 0
|
Re: PHP help
You'd almost be better off splitting it up into an array and then checking the length of the last element.
<?php
$Host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
print $Host;
print "<br>";
$ArHost = split("\.",$Host);
$iSizeArr = count($ArHost);
If (strlen(end($ArHost)) < 3) {
#HOST HAS A 2-CHAR TOP LEVEL - IE: COUNTRY CODE
echo "domain name is: " . $ArHost[$iSizeArr-3] . "." . $ArHost[$iSizeArr-2] . "." . $ArHost[$iSizeArr-1] . "\n";
} else {
#HOST IS TYPICAL 3-CHAR TOP LEVEL
echo "domain name is: " . $ArHost[$iSizeArr-2] . "." . $ArHost[$iSizeArr-1] . "\n";
}
?>
Hope this helps.
Jessica.
|
|
|
|
|
|
|
quote
|
|
06-01-2004, 08:29 PM
|
#4
|
|
Guest
Posts: n/a/0
Threads:
|
Re: PHP help
dividing it into an array as Jessicaq says above is definitely your best bet.
|
|
|
|
|
|
|
quote
|
|
06-09-2004, 05:17 PM
|
#5
|
|
whore
Join Date: Jan 2004
Location: 2nd biggest state
Posts: 27/0.02
Threads: 0
|
Re: PHP help
I'll give it a shot..been away from the computer a while..errr
|
|
|
|
|
|
|
quote
|
|
06-09-2004, 09:42 PM
|
#6
|
|
whore
Join Date: Jun 2004
Location: SoCal
Posts: 364/0.22
Threads: 0
|
Re: PHP help
Cool. Let me know if you need more advice.
Jessica.
|
|
|
|
|
|
|
quote
|
|
|