Drupal 7: How to get user’s IP or hostname ?

In Drupal 7 how to find out any guest user or registered user’s IP address or hostname?

The answer is we can use session_id() which is stored in the ‘session’ table in the D7. It can return current user’s IP address or hostname by using session-id whether user is a guest or registered member.
So I write a function you can find it here.



About Tanveer
RIA (Rich Internet Application) Developer with a wide variety of business applications. Particularly interested in client/server and relational database design. Always interested in migration projects, as well as close interaction with the DB manufacturers.

2 Responses to Drupal 7: How to get user’s IP or hostname ?

  1. Jeannine says:

    Thanks , I’ve just been looking for info approximately this subject for a
    while and yours is the best I’ve came upon so far. But, what in regards to the bottom line?
    Are you positive in regards to the source?

    • Tanveer says:

      Hi Jeannine,

      Thanks for you nice comment. The bottom line is the source code that I have hosted on GitHub for better understanding. If you have any better suggestion then please let me know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: