Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP5: What PHP function outputs Users IP address, Platform and Browser?

Of all these functions that return current visitors info/ip only the first one seems to output:

echo $_SERVER["REMOTE_ADDR"];

echo $_SERVER["HTTP_X_FORWARDED"];
echo $_SERVER["HTTP_X_CLUSTER_CLIENT_IP"];
echo $_SERVER["HTTP_FORWARDED_FOR"];
echo $_SERVER["HTTP_FORWARDED"];

Primary Question: Why the other functions dont output anything?

Bonus Question: Are there any other cool functions in this regard for example a function that outputs the visitors used browser & platform?? Also usefull would be to get the visitors city, favourite beverage, favourite color in #RGB... :) Thanks for any suggestions!

like image 795
Sam Avatar asked Jan 21 '23 01:01

Sam


2 Answers

  1. It's not functions but array members.
  2. It's not IP address they output but HTTP headers (Note HTTP_ in them)
  3. The only one contains IP address is $_SERVER["REMOTE_ADDR"]

Why the other functions dont output anything?

Because these HTTP headers are optional.

Are there any other cool functions

Sure

print_r($_SERVER);

will show you them all

Note get_browser() function which helps you to get more structured info out of User-Agent header.

like image 108
Your Common Sense Avatar answered Apr 27 '23 12:04

Your Common Sense


Using $_SERVER['HTTP_USER_AGENT'] will get you something like:

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3

Which you can use to work out the operating system and browser.

like image 26
Twelve47 Avatar answered Apr 27 '23 12:04

Twelve47