Hi all,

How to retrieve client's ip address, mac address, and others hardware address ?
Also, how to detect user end device (whether computer, notebook, pda, ...) ?

Is that all possible ?


Thanks, :)

The $_SERVER superglobal array contains such information. For example,

$ipAddress = $_SERVER["REMOTE_ADDR"];

Try a var_dump on your $_SERVER array and you will see all of the information that it contains.

EDIT: Not sure about the device, but the OS should be available in the $_SERVER array, let me know if I'm wrong but from memory it is. The OS will often give a strong indication as to the device type so should be suitable for most practical purposes.

The $_SERVER superglobal array contains such information. For example,

$ipAddress = $_SERVER["REMOTE_ADDR"];

Try a var_dump on your $_SERVER array and you will see all of the information that it contains.

EDIT: Not sure about the device, but the OS should be available in the $_SERVER array, let me know if I'm wrong but from memory it is. The OS will often give a strong indication as to the device type so should be suitable for most practical purposes.

Thanks for the reply.

With $ipAddress = $_SERVER i get an ipAddress. But it different from my PC ipAddress. i guess that it was the ipAddress router :?: Is it possible to get my real ipAddress ?

i don't get about var_dump. but do you mean variance in $_SERVER ? All i know are :

$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER
$_SERVER

is it possible for $_SERVER to distuingish user end device ? :)

assuming the need for a browser sniffer for handheld devices this gets most

<?php $mobile = "http://m.mysite.com/";
if(preg_match('/Windows CE/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Blackberry/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmSource/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/SymbianOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Opera Mini/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Nokia/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Samsung/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/vodaphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Jphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/AvantGo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DoCoMo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DDIPOCKET/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
// redirect to pda page else continue
ob_start("ob_gzhandler"); ?>
commented: Excellent post +3

assuming the need for a browser sniffer for handheld devices this gets most

<?php $mobile = "http://m.mysite.com/";
if(preg_match('/Windows CE/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Blackberry/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmSource/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/SymbianOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Opera Mini/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Nokia/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Samsung/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/vodaphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Jphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/AvantGo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DoCoMo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DDIPOCKET/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
// redirect to pda page else continue
ob_start("ob_gzhandler"); ?>

Thanks for the reply,

It works, thanks :) But still got confuse with the differences between pda & phone, pc & notebook :?:

sorry theyre in order of ability, down to opera mini are nominally pda, below nim,inally phones
some pda like early blckberry are less competent than newer phones, but ...

sorry theyre in order of ability, down to opera mini are nominally pda, below nim,inally phones
some pda like early blckberry are less competent than newer phones, but ...

Thanks for the reply,

do you mean that i should check the OS used in that device :?: like blackberry OS so it should be mobile phone, windows ce should be pda, and so on :)

those are user_agents :P
it is reasonable to assume that a portable device that reports that user_agent has the minimum standards of the browser
windows ce has good javascript, pretty much full xhtml support, full mouse support (touch screen +tap)
blackberry works ok, with typically lousy javascript
a device running opera mini, can display everything,
I use the opera mini demo to preview webpages http://demo.opera-mini.net/demo.html?www.yoursite.com handheld
It is impossible to really get hardware details
all can be spoofed
its most functional (i think) to display what the user_agent says it can display, from http_accept user_agent etc off the $_server array

the m. subdomain has minimized images & code most handheld users pay per byte, and have low d/l speed.

ramble
ramble

those are user_agents :P
it is reasonable to assume that a portable device that reports that user_agent has the minimum standards of the browser
windows ce has good javascript, pretty much full xhtml support, full mouse support (touch screen +tap)
blackberry works ok, with typically lousy javascript
a device running opera mini, can display everything,
I use the opera mini demo to preview webpages http://demo.opera-mini.net/demo.html?www.yoursite.com handheld
It is impossible to really get hardware details
all can be spoofed
its most functional (i think) to display what the user_agent says it can display, from http_accept user_agent etc off the $_server array

the m. subdomain has minimized images & code most handheld users pay per byte, and have low d/l speed.

ramble
ramble

Thanks for the reply,


Oh, it is user_agent :D

Is the $_Server array i mentioned earlier is complete ? :)

Is the $_Server array i mentioned earlier is complete ? :)

dunno, I use the same four for most of the detections I need,
I look at php.net helpscreens whenever I want something other than http_accept http_user_agent php_self http_referer and usually forget it as soon as the code works
headslap moment

Is the $_Server array i mentioned earlier is complete ?

var_dump($_SERVER);

will let you know for sure.

var_dump($_SERVER);

will let you know for sure.

Thanks for the reply,

How to write the code. is it right :

var_dump($_SERVER);
echo var_dump;

but, it's not display anything :(

Thank you :)

Sorry try

print_r(var_dump($_SERVER));

Sorry try

print_r(var_dump($_SERVER));

Thanks for the reply,

it is display all about $_SERVER :)
but, still can't find the client's unique address.
i have search on how to get that, and it says to use whether exec(), system(), passthru(), shell_exec() or popen. And here is the code i have try :

ob_start(); // Turn on output buffering
system(‘ipconfig /all’); //Execute external program to display output
$mycom=ob_get_contents(); // Capture the output into a variable
ob_clean(); // Clean (erase) the output buffer

$findme = “Physical”;
$pmac = strpos($mycom, $findme); // Find the position of Physical text
$mac=substr($mycom,($pmac+36),17); // Get Physical Address

echo $mac;

but still can't display anything. i try using var_dump too and it display NULL.

need some advice here :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.