Jump to content
xisto Community
Sign in to follow this  
PureHeart

How Can I Get User's Ip

Recommended Posts

I'm a PHP coder.

I saw many sites that read user's IP address and display on the page (like some free dns website). They also let me know where I am (the country).

 

So, my question is.

How to know user's IP address. .

 

Remember, I'm using PHP

 

Please include the code in reply.

Share this post


Link to post
Share on other sites

So I think it goes something like this:

 

<?php

 

$test=getenv("REMOTE_ADDR");

 

echo $test;

?>

 

Try it out.  :mellow:

1064325352[/snapback]


Yeah, it worked. Thank you very much.

Share this post


Link to post
Share on other sites

Yeah, it worked. Thank you very much.

1064325354[/snapback]


there is a more common way to do it.

 

<?php $test = $_SERVER['REMOTE_ADDR']; echo $test;?>

u can get alot of information about the user, u can use

<?phpphpinfo();?>
to get all the variables...

Share this post


Link to post
Share on other sites

Most all sites that use PHP use such schemes to kick certain IPs off the site usually forums and CMS need this to keep abusive people off the site. PHP-Nuke, Mamba Xoops, Invision, PHPbb, and many other such systems already track the IPs and if necessary the administrator can ban that IP...How do you think people get banned from these forums, it is not by their user name necessarily but the IP.

Share this post


Link to post
Share on other sites

How do you think people get banned from these forums, it is not by their user name necessarily but the IP.

But what if I have a new IP every time I visit the forum? Me for example, I get a dynamic IP adress assigend by my provider everytime I enter the interent. I think I can't be banned by a forum administrator except if he tries to ban ALL IP adresses coming from a certain IP range.

Share this post


Link to post
Share on other sites

That is simple, you ban the IP as well as the User, but that should go without saying then you if baneed unless you have a few hundred email addresses, and can come up with some unique usernames you will probably not be aloowed back on.

Share this post


Link to post
Share on other sites

That is simple, you ban the IP as well as the User, but that should go without saying then you if baneed unless you have a few hundred email addresses, and can come up with some unique usernames you will probably not be aloowed back on.

1064325960[/snapback]


Just to clear this up, users will not be banned by IP addresses due to their dynamic nature and that we may accidently ban people who should not be banned.

 

We ban the user and their email address. They can continue registering with a new username and email address, and we will continue banning them if they step out of line again. They think they can register over a hundred emails, good, because we can ban over a hundred emails too and we don't mind doing our job. Eventually they will get sick of this, and no doubt we would be sick of it too, but we won't give up since that is our job of making sure we keep our forums to an acceptable level.

 

Cheers,

 

 

MC

Share this post


Link to post
Share on other sites

As far as I am aware, there are several ways in which to ban someone.1. Remove all the privilages for that account, so it literally becomes null.2. Delete the account.3. Ban username4. Ban IPIf it is possible to use PHP to find the TRUE IP, instead of a dynamic one, then banning would be a bit easier. And as MC pointed out, it is the job of the admin/mods to maintain that problem accounts are banned. People who get banned once, are more often than not banned again and again due to their repetitive defiance. Those people always have the same mannerisms, so it is easy to spot them.

Share this post


Link to post
Share on other sites

If it is possible to use PHP to find the TRUE IP, instead of a dynamic one, then banning would be a bit easier.

1064326031[/snapback]


There is no such thing as TRUE IP. Or to put it other way around dynamic IPs are just as true as any. DHCP servers just hand out random IP addresses to clients connecting. They have no other addresses.

 

Now the only truly unique address each client has is the MAC address of the NIC or cabel modem's or whatever. But these are not sent on HTTP requests.

 

 

And when banning IP addresses dynamic addressing isn't the only issue. Proxy servers and NATs are far more worse. Ban the proxy's or NAT gateways address and you ban all people behind it. This could mean several thousand clients.

Share this post


Link to post
Share on other sites

Actually, the $_SERVER and $_ENV are PHP superglobalsvariables that are capable of retrieving a lot of very useful information. You should already be familiar with the $_POST and $_GET superglobals.

At some point in time you should try to learn how to use the $_COOKIE and $_SESSION superglobals. It gives you a lot of options for user specific options and authentication.

To learn more, see the PHP Documentation about PHP Predefined variables.

Hope you find this usefull. :mellow:

vujsa

Share this post


Link to post
Share on other sites

At some point in time you should try to learn how to use the $_COOKIE and $_SESSION superglobals.  It gives you a lot of options for user specific options and authentication.

 

1064326073[/snapback]


Word.

 

Definitely worth studying. The thing about stuff like this is that, even though you might not have immediate use for them, by studying you'll know that they do exist and what stuff you can do with them. Generally speaking PHP manual is worth glancing through entirely. It is sometimes so frustrating when you have spend time implementing something yourself to notice that it is already built in the language.

Share this post


Link to post
Share on other sites

There is no such thing as TRUE IP. Or to put it other way around dynamic IPs are just as true as any. DHCP servers just hand out random IP addresses to clients connecting. They have no other addresses.

 

Now the only truly unique address each client has is the MAC address of the NIC or cabel modem's or whatever. But these are not sent on HTTP requests.

And when banning IP addresses dynamic addressing isn't the only issue. Proxy servers and NATs are far more worse. Ban the proxy's or NAT gateways address and you ban all people behind it. This could mean several thousand clients.

1064326036[/snapback]

Thanks for clearing that up. IP and connected technologies are not my forte.

 

Wouldn't it be easier if we all had a single state IP instead of this dynamic system?

Share this post


Link to post
Share on other sites

Wouldn't it be easier if we all had a single state IP instead of this dynamic system?

1064328011[/snapback]


Yes it would. But there is a reason why this isn't the case: there aren't enough addresses! The version four of the IP protocol is the one that's commonly used now. IPv4 supports 32-bit addresses, meaning that there can some 4 billion different addresses. And as you know, more and more computers and other appliances (especially cell phones) are getting connected Internet is getting more and more popular in the population rich asian countries. When Internet originated, the number of connected computers were hugely underestimated. Other problem is that the addresses aren't equally distributed. As Internet originated in the USA, US companies get to reserve address ranges first. You could say that USA is hogging IPv4 addresses.

 

But there is a cure for this: the IPv6. Yes, that's not typo, they decided to skip the version 5. IPv6 has 128-bit addressing, which means some 3.4 Ă 10^38 addresses. I remember hearing that the number of addresses are enough to have several addresses for each atom of every human being alive. Yep, they screwed up with the IPv4 addresses and with Ipv6 they go to overkill ;) One lecturer said that once the intellectual clothing becomes popular they're probably going to assign each button a couple of IPv6 addresses...

Share this post


Link to post
Share on other sites

Well, 2,305,843,009,213,693,952 individual addresses can be used for IPv6. This is better than the IPv4, helps with security and is a lot more long-term.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.