IP Addresses and PHP
What is an IP address? IP address is short for Internet Protocol address.
Being able to look up a user's IP address is a very useful tool. Your IP address is a set of numbers that are unique to your internet connection. An IP address from Wisconsin would look very different then an IP address from Australia, so one reason to look up a users IP address is if you have location specific content. You may also use it for target advertising that may only apply to people in a certain area, or for redirecting them to relevant news or weather content for people at their location.
An IP address consists of four blocks of numbers separated with periods. The values of the numbers can range between 0 and 225. The individual sets of numbers within the IP address are referred to as an octet. This is because each of the four octets that comprise an IP address consist of eight bits. This makes your entire IP address a 32 bit piece of information. Your IP address is issued to you by your ISP (short for internet service provider.) An IP address can be static or dynamic. If you have a static IP address it will always be the same, however if you have a dynamic address it can end up changing.
It is important to note that there is a difference between an internal IP address and an external IP address. When your have several devices connected to the same router, they will all have a different internal IP address. If you were to check, you would find that all of these devices are sharing the same external IP address because they are all using the same connection to your ISP. General the last two numbers of the internal address are the order in which you connected to the network.
If you were to reboot your router your internal IP address could change, but your external IP address would not be effected in any way.
Using PHP you can look up the user's external IP address by using the getenv () function. Here is an example of how you would do that:
If you are running an interactive site, it may be useful to store a record of user's IP addresses. On things like forums where you may not wish to allow a person more than one account, you can check for duplicate IP addresses to keep people from pretending to be multiple people. You can also see if someone is suddenly logging in from an odd area, or if there is suspicious activity you can record where failed login attempts are coming from. If someone tries to hack your system their IP address is like a foot print to help point to the culprit.
Another use for recording IP addresses is to use them as a black list for spammers. When someone is a known spammer you can blocks posts, comments, or new accounts form being made by someone from that specific IP address that you have chosen to black list. Although this is not a fool proof technique (because people can still use proxy servers) it does help cut down on a lot of spam.
You could provide IP address lookup as a service to curious visitors as well. WhatIsMyIP.com is a very popular site that simply tells a user what IP address they are located at. Sometimes this information is helpful to have, especially if you are trying to connect to a friend's computer remotely.
Being able to look up a user's IP address is a very useful tool. Your IP address is a set of numbers that are unique to your internet connection. An IP address from Wisconsin would look very different then an IP address from Australia, so one reason to look up a users IP address is if you have location specific content. You may also use it for target advertising that may only apply to people in a certain area, or for redirecting them to relevant news or weather content for people at their location.
An IP address consists of four blocks of numbers separated with periods. The values of the numbers can range between 0 and 225. The individual sets of numbers within the IP address are referred to as an octet. This is because each of the four octets that comprise an IP address consist of eight bits. This makes your entire IP address a 32 bit piece of information. Your IP address is issued to you by your ISP (short for internet service provider.) An IP address can be static or dynamic. If you have a static IP address it will always be the same, however if you have a dynamic address it can end up changing.
It is important to note that there is a difference between an internal IP address and an external IP address. When your have several devices connected to the same router, they will all have a different internal IP address. If you were to check, you would find that all of these devices are sharing the same external IP address because they are all using the same connection to your ISP. General the last two numbers of the internal address are the order in which you connected to the network.
If you were to reboot your router your internal IP address could change, but your external IP address would not be effected in any way.
Using PHP you can look up the user's external IP address by using the getenv () function. Here is an example of how you would do that:
<?php $ip = getenv("REMOTE_ADDR") ; Echo "Your IP is " . $ip; ?>
If you are running an interactive site, it may be useful to store a record of user's IP addresses. On things like forums where you may not wish to allow a person more than one account, you can check for duplicate IP addresses to keep people from pretending to be multiple people. You can also see if someone is suddenly logging in from an odd area, or if there is suspicious activity you can record where failed login attempts are coming from. If someone tries to hack your system their IP address is like a foot print to help point to the culprit.
Another use for recording IP addresses is to use them as a black list for spammers. When someone is a known spammer you can blocks posts, comments, or new accounts form being made by someone from that specific IP address that you have chosen to black list. Although this is not a fool proof technique (because people can still use proxy servers) it does help cut down on a lot of spam.
You could provide IP address lookup as a service to curious visitors as well. WhatIsMyIP.com is a very popular site that simply tells a user what IP address they are located at. Sometimes this information is helpful to have, especially if you are trying to connect to a friend's computer remotely.