Tuesday, 9 June 2020

php ipaddress

<?php
$_SERVER ['REMOTE_ADDR'];
how to print ipaddreess
In local server it shows some problem while getting ipaddress
so go to xampp- apache- conf-  httpd.confic- use notepad open
listen search, find next - listen 80- listen 127.0.0.1:80 write, then ur problem is over
stop apache ,after 5 seconds use
how to block ip address
<?php
$ipadress =$_SERVER ['REMOTE_ADDR'];
how to show my ip adress
$i_blocked = array('127.0.0.1', '10.0.0.10');
store some ipaddress using array to one variable
?>
<?php
require 'confinc.php';
using template get the values like bootstrap
foreach($ipadress as $ip){
using foreach convert the variable name
echo $ip. '<br>';
prints the present ip, we not use the function , we use the function in confinc page , get that using require
}
?>
<?php
require 'confinc.php';
prints the present ip, we not use the function , we use the function in confinc page , get that using require
foreach($ip_blocked as $ip){
convet just for understanidng way
if ($ip == $ipadress) {
compares the ip adreess which is in blocked list
die (' your ip adress ' .$ip_address.' has been blocked!');
it wil not execute the next statements
}
if it there, it wil not the execute the next statements use die
}
?>
how to get ip adress
  1. <?php  
  2. echo 'User IP Address - '.$_SERVER['REMOTE_ADDR'];  
  3. ?>  
if ipadress is not come if customer using proxy
  1. <?php  
  2.     function getIPAddress() {  
  3.     //whether ip is from the share internet  
  4.      if(!emptyempty($_SERVER['HTTP_CLIENT_IP'])) {  
  5.                 $ip = $_SERVER['HTTP_CLIENT_IP'];  
  6.         }  
  7.     //whether ip is from the proxy  
  8.     elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
  9.                 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
  10.      }  
  11. //whether ip is from the remote address  
  12.     else{  
  13.              $ip = $_SERVER['REMOTE_ADDR'];  
  14.      }  
  15.      return $ip;  
  16. }  
  17. $ip = getIPAddress();  
  18. echo 'User Real IP Address - '.$ip;  
  19. ?>  





another ip


// Function to get the client ip address
function get_client_ip_env() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
        $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}


how to get the ipaddress if used proxy


// Function to get the client ip address
function get_client_ip_server() {
    $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP'])
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if($_SERVER['HTTP_X_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if($_SERVER['HTTP_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}


-------------

get the ipadress of website

  1. <?php  
  2. $ip_address = gethostbyname("www.google.com");  
  3. echo "IP Address of Google is - ".$ip_address;  
  4. echo "</br>";  
  5. $ip_address = gethostbyname("www.javatpoint.com");  
  6. echo "IP Address of javaTpoint is - ".$ip_address;  
  7. ?>  




$_SERVER ['REMOTE_ADDR'];
array
require
foreach
foreach
if
die
how toprint the present ip address or stor the ipadress to a variable
how tostore some values into a variable using array
using template
how to print present ip adreess
is it useful foreach to converto variable
can we compare the ipadress with blocked address, ?
if it true, some statement
can we tell if ur adress is bloicked



No comments:

Post a Comment