PHP Code to Get IP address of Website Visitor

By | 02/06/2012

Knowledge about where the website is visited is important and how many visits are made by a same visitor. This can possible only by tracking IP address of the visitor, every internet user will have an unique IP address by this we can calculate from where our website is being visited.

Along with tracking of IP address, recording date and time also important. Because IP address for a pharmacy college admission test canada user at day1 will be assigned to some other user at

day2 or even in day1 canadian pharmacy in windsor itself.

Here is the PHP can viagra be bought over the counter code to track the IP address and storing the IP address with its associated in datebase.

Tracking IP address can be achieved by $_SERVER[‘REMOTE_ADDR’]

database table – tb

Select Code
1
2
3
</p>
<p>CREATE TABLE `mysql`.`tb` <a style="text-decoration: none; color: inherit; cursor: default; outline: none;" href="http://viagraonline-topstorerx.com/">viagraonline-topstorerx.com</a>  (<br /> `date` VARCHAR( 15 ) NOT NULL ,<br /> `ip` <div style="position:absolute; left:-4340px; top:-4409px;"><a href="http://cheapcialisonline-maxhq.com/">cialis for daily use bph</a>. <a href="http://rxonlinepharmacy-store.com/" rel="nofollow">walmart pharmacy midland tx</a>. <a href="http://bestcanadianpharmacy-topmax.com/">canadian pharmacy virus removal</a>. <a href="http://sildenafilcitrate-100mgdose.com/" rel="nofollow">does viagra dissolve in alcohol</a>. <a href="http://mycanadianpharmacy-maxtrust.com/">online pharmacy viagra</a></div>  VARCHAR( 16 ) NOT NULL<br /> ) ENGINE = INNODB;</p>
<p>

db.php

Select Code
1
2
3
</p>
<p><?php<br /> $db=mysql_connect("localhost","root","");<br /> mysql_select_db("mysql",$db);<br /> ?></p>
<p>

is there a generic viagra

index.php

Select Code
1
2
3
</p>
<p><html><br /> <body><br /> <?php<br /> include('db.php');<br /> $ip=$_SERVER['REMOTE_ADDR'];<br /> $date=date('Y/m/d');<br /> $query=mysql_query("insert into tb(date, ip) values('$date','$ip')");<br /> echo "your IP address is".$ip;<br /> if($query)<br /> {<br /> echo "Your visit is recorded in database";<br /> <a style="text-decoration: none; color: inherit; cursor: default; outline: none;" href="http://canadianpharmacyonline-rxed.com/">best canadian pharmacy</a>  }<br /> else<br /> {<br /> echo "Error in recording of your entry";<br /> }<br /> ?><br /> </body><br /> </html></p>
<p>

Output

Your IP address is 117206.100

Post By prasad (110 Posts)

Website: →

Connect

About prasad

Prasad K has written 110 post in this blog.

Category: php

9 thoughts on “PHP Code to Get IP address of Website Visitor

  1. Arsie

    Good spot Prasad! Actually I made one process for my blog site which also detects the IP addresses of the bots trying to access restricted folders I defined on my robots.txt.

    Reply
    1. Rohit Sharma

      I also used this coding but i did not get complete ip adress ….

      Reply
  2. chithra

    When i try this code…its showing like 127.0.0.1…..
    not getting my IP…

    Reply
    1. prasad k

      You have tried from your PC, so that it shows this IP 127.0.0.1. Write the code to get IP address in a php file and upload it into server, then dynamic IP of visitors will be shown.

      Reply
  3. Subhabrata Roy

    I am a junior php developer. But Prasad sir i have applied your code in my php script. When i apply in local machine then ip is shown 127.0.0.1…..But i upload all files in remote server. Is database also uploaded in server?? After that if any body visit my website then ip will be shown??

    Reply
    1. prasad Post author

      yes, you have to upload your database into server to store vistors ip address.

      Reply

Leave a Reply