SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

PHP script to Find out IP address

We can get the IP address of any visitor by using PHP. Finding the IP address is very important requirement for many scripts where we store the members or visitors details. For security reason we can store IP address of our visitors who are doing any purchases or recording the geographical location of the visitor can be done this way. Some time based on the IP address we can redirect the browser to different areas of the site. There are many applications using this and here is the PHP code to know the IP address of any visitor to the site.

$ip=@$REMOTE_ADDR;
echo "<b>IP Address= $ip</b>";


The above code will display this IP address= 38.107.191.95

IP address if the register_global is off
If at php.ini if register_global is set to Off then we have to change the script a bit to get the address. Here it is

$ip=$_SERVER['REMOTE_ADDR'];

You can see the modification done to signup & login script if global variable is OFF
We can convert the dot formatted IP address to number by using ip2long function and store in MySQL database.

Same way you can find out the referrer to your site by using PHP.


How to get IP address in ASP ?

Read article on visitor tracking

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) in /home/smo123/public_html/tracking/track.php on line 8
Could not connect to MySQL