Getting Ip

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Getting Ip

khalilov
Whats the php code to get the users IP, i want to start a referal program and i don't want to people to refer themselves:P

Reply

FirefoxRocks
The IP address is stored in a $_SERVER[] variable, in this case it is the REMOTE_ADDR variable. So it would be:
CODE
$_SERVER['remote_addr'];


If you want to store that in a variable (which you probably can figure out) and display it, you do this:
CODE
$ip = $_SERVER['remote_addr'];
echo($ip);

Reply

Jeigh
You've probably already thought of this, but you might want to store a long term cookie as a secondary check. IP's don't change a lot anymore but they can still depending on the connection type or the users dedication lol, so adding a little cookie when they register just sort of adds a second layer that they would need to think to clear in order to get around your checks. Then again if it's not that important and you just want to limit it from happening frequently then the IP thing would be more then enough obviously.

Reply

sparkx
Just a side message there is NO way to track internet users other then real-time IP lookup or backtracking (which is very hard to do and is usually only used in movies). I would say probably not to even bother making a script like this but rather only accept the referral if the new user is active (for example if it is a forum then make a minimum of 10 posts and remove the referral if the new user gets banned for spamming est.). If one person wants to do that much work just to get a referral then let them have it...

Remember Cookies can be edited or deleted and IPs can be changed in less then 30 seconds.

Hope this helps,
Sparkx

Reply

levimage
Do you mean like how some online messenger/chat(s) detect if more than one user logs in or is logged in from an IP address or if someone from a specific ip is creating multiple user accounts within a certain time period. Maybe you should just have like a cool off period verses denying or banning someone. Cause their may be multiple people using your services from the same place like a pubic wifi, school, or building.

Just something to think about.

Reply

Quatrux
Here is also a way to get the ip address from a user using php language, even though this is not the best method, but I am using it and don't really have problems, I will show this example in a class, those who know php could easily just change it or something like that smile.gif

CODE
class MyClass {

    /**
     * @access public
     * @variables
     */

    var $ipAddress, $proxyAddress = '';

    function setIPAddress() {

            if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

                if (isset($_SERVER['HTTP_CLIENT_IP'])) { $this->proxyAddress = $_SERVER['HTTP_CLIENT_IP']; }
                else                                                 { $this->proxyAddress = $_SERVER['REMOTE_ADDR']; }
                                                                      $this->ipAddress    = $_SERVER['HTTP_X_FORWARDED_FOR']; }
        elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {      $this->ipAddress    = $_SERVER['HTTP_CLIENT_IP']; }
          else                                                  {      $this->ipAddress    = $_SERVER['REMOTE_ADDR']; }

    }
}


and whenever you want to show the ip address you just do:

$MyClass = new MyClass();

and you can call the function once like $Myclass->setIPAddress(); and you'll get the value and you could use it like this:

echo $MyClass->ipAddress or echo $MyClass->proxyAddress but I would do it in a constructor of that class, the class constructor is a function/method of that class and needs to have the same name as the class in other languages it also can be init() like on Zend framework on PHP.. A constructor here is good because this function needs to be done/executed/called only once, also it could be done differently as I said, but this is just one of a lot of methods which is possible.

 

 

 


Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. getting - 16.69 hr back. (1)
  2. tracking ipaddres - 61.48 hr back. (1)
Similar Topics
Looking for ip






*SIMILAR VIDEOS*
Searching Video's for ip
advertisement




Getting Ip