“Comment obtenir l'adresse IPv4 dans PHP” Réponses codées

Comment obtenir l'adresse IP du client à l'aide de PHP

The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.

Get the IP address of the website
<?php
echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
?>
  
/*
I Hope it will help you.
Namaste
Stay Home Stay Safe
*/
Ankur

Comment obtenir l'adresse IPv4 dans PHP

// Function to get the user IP address
function getUserIP() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
Hilarious Horse

Obtenez IP utilisateur en php

function getIp() {
    $ip = $_SERVER['REMOTE_ADDR'];
 
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
 
    return $ip;
}
vmxes

php obtient le client IP

$_SERVER['REMOTE_ADDR']
Black Bird

Réponses similaires à “Comment obtenir l'adresse IPv4 dans PHP”

Questions similaires à “Comment obtenir l'adresse IPv4 dans PHP”

Plus de réponses similaires à “Comment obtenir l'adresse IPv4 dans PHP” dans C++

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code