Click here to Skip to main content
15,124,736 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hi,
I was browsing the internet to find out how to create php page access counter. Many of php access counter I have found were based on counting different IPs.

1) Is it the only way or the best way how to count it?

I was wondering about it... What will happen if two computers from the same computer network with different local ips connect to the page? They will have the same global ip, because they have the same router, right? So the counter will recognize these two computers as one?

Here is a code I have found and rewrited to my script:
PHP
$ipaddress = "";
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
    $ipaddress = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
else
    $ipaddress = $_SERVER["REMOTE_ADDR"];


2) So, I would like to fix it to recognize different computers from the same network by mac or I don't know how and improve the code if it does not work correctly always, because I have read that this will not work correctly always.

Thanks for replies!
Pepin z Hane
Posted

1 solution

What about this? Get the user's MAC! I think it's a quite hardcore, but it works.
PHP
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;
?>


Pepin z Hane
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900