My Blog

I'll share what I think & have learned with you

How to grab an ip address and put it into a MySQL table

By Pavan Katepalli

Image taken from

I recently tried to grab the ip address of a user signing up to INRtracker.

My strategy was to use some back end PHP code to grab the ip address and then insert it into one of our MySQL tables.


However, I ran into some trouble.

When I used $_SERVER, the code would run.

But nothing would go into the MySQL table.

ip2long is the answer

Then I thought, maybe it's because I'm using varchar for the MySQL column structure. So instead I decided to change the structure of the column to an unsigned integer.

But, I had to convert the ip into an integer, so I did a quick search on Google before I started coding away – and I found this post: that shows how to do this with a PHP function called ip2long.

Why Internal Tracking Is Important

The purpose of keeping track of the ip address of registered users on INR Tracker is to learn how and when users are using our website.

Google Analytics in my opinion is only one part of the puzzle.

wWen you want to track stats for when your users are logged into your site, it's best to do it on your own.

My business partner came up with this as part of our product management strategy.

This way we can figure out what parts of the site we should dedicate our time toward and what parts we should possibly drop.

If everyone's using one part of the site, then we know we should improve that more.

Consequently, if everyone's not using another part of the site, then we know we shouldn't waste our time on improving that part of the site.


Keywords For Search Engines


Subscribe to New Posts

Recent Comments

  • Hey Sayanaël I’m glad the post helped you out! I switched from windows to mac and then mac to ubuntu, so I forget how to refresh wamp. Do you pull up the wamp menu and click on refresh?

    Pavan in Cake PHP 2.2.1 Installation Errors
  • Thanks for this solution ! After hours browsing internet, your solution work just fine ! P.S: You don’t have to restart wamp, just refresh it.

    Sayanaël in Cake PHP 2.2.1 Installation Errors
  • Great article Pavan! Hopefully I can use a lot of these tips to further my own coding experience.

    Joe in How I Learned to Code For My Start Up

Want to get started?

You've got an idea and I'll code it fast and make it look great.