/    Sign up×
Community /Pin to ProfileBookmark

What is the code

Just a quick question
What is the code that finds the browser,OS and ip address.
And where do i put it. :rolleyes:

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsAug 15.2005 — $_SERVER['HTTP_USER_AGENT']
$_SERVER['REMOTE_ADDR']
Copy linkTweet thisAlerts:
@Stephen_PhilbinAug 15.2005 — Firewalls can (and often do) prevent the sending of info like refferers, browser data, and OS info though. Don't go building any applications that depend on that sort of info to work. It just won't work for a very large number of people.
Copy linkTweet thisAlerts:
@bokehAug 15.2005 — $_SERVER['REMOTE_ADDR'] may be a proxy and not the user's IP.
Copy linkTweet thisAlerts:
@ShrineDesignsAug 15.2005 — i converted this from python to php (bittorrent)[code=php]function _get_forwarded_ip($headers)
{
if(array_key_exists('HTTP_X_FORWARDED_FOR', $headers))
{
$h = $headers['HTTP_X_FORWARDED_FOR'];

if(strpos($h, ','))
{
list($x, $y) = explode(',', $h);

if(!is_local_ip($x))
{
return $x;
}
return $y;
}
else
{
return $h;
}
}
if(array_key_exists('HTTP_CLIENT_IP', $headers))
{
return $headers['HTTP_CLIENT_IP'];
}
if(array_key_exists('HTTP_VIA', $headers))
{
if(preg_match("([0-9.]+)Z", $headers['HTTP_VIA'], $x))
{
return $x[1];
}
}
if(array_key_exists('HTTP_FROM', $headers))
{
return $headers['HTTP_FROM'];
}
}
function get_forwarded_ip($headers)
{
$x = _get_forwarded_ip($headers);

if(is_null($x) || !is_valid_ipv4($x) || is_local_ip($x))
{
return NULL;
}
return $x;
}
function is_valid_ipv4($ip)
{
$a = explode('.', $ip);

if(count($a) != 4)
{
return false;
}
foreach($a as $x)
{
if($x > 255 || $x < 0)
{
return false;
}
}
return true;
}
function is_local_ip($ip)
{
$v = explode('.', $ip);

if($v[0] == 10 || $v[0] == 127 || in_array(array_slice($v, 0, 2), array(array(192, 168), array(169, 254))))
{
return true;
}
if($v[0] == 172 && $v[1] >= 16 && $v[1] <= 31)
{
return true;
}
return false;
}[/code]
example[code=php]<?php
// ...
$_SYSTEM = array_merge($_SERVER, $_ENV);

$ip = $_SERVER['REMOTE_ADDR'];
$nip = get_forwarded_ip($_SYSTEM);

if($nip && is_local_ip($ip))
{
$ip = $nip;
}
// ...
?>[/code]
×

Success!

Help @Mausau2000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...