Clive Walkden

PHP, MySQL, HTML5, CSS3, jQuery code and ideas.

PHP Posts

PHP Function to return your IP address

PHP Function to return your IP address

in PHP
by
with 0 Comments

 

Here's a quick little function which can be used to return your IP address
 
[code lang="php"]
function getRemoteIPAddress() {
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
[/code]
 
The result can be very handy when combined with an if statement to code  parts of a site you don't want the end user to see. Just remember you need to know your IP address before you can create the statement below.
 
[code lang="php"]
$ip = getRemoteIPAddress();
 
if($ip == "insert your IP here") {
//run the code only you want to see here
}
[/code]
comments powered by Disqus