'is there a way to get clients IP addresses through this PHP form
is there a way to get clients IP addresses through this PHP form or can someone help the right way to get the ip adress here.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['name','phone','email'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);
$validator->field('countryCode')->maxLength(20);
$validator->field('phone')->maxLength(20);
$pp->requireCaptcha();
$pp = getIPAddress($_SERVER['REMOTE_ADDR']);
$pp->sendEmailTo('[email protected]');
echo $pp->process($_POST);
Solution 1:[1]
try this
<?php
function getRealIP(){
if (isset($_SERVER["HTTP_CLIENT_IP"])){
return $_SERVER["HTTP_CLIENT_IP"];
}elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
return $_SERVER["HTTP_X_FORWARDED_FOR"];
}elseif (isset($_SERVER["HTTP_X_FORWARDED"])){
return $_SERVER["HTTP_X_FORWARDED"];
}elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])){
return $_SERVER["HTTP_FORWARDED_FOR"];
}elseif (isset($_SERVER["HTTP_FORWARDED"])){
return $_SERVER["HTTP_FORWARDED"];
}else{
return $_SERVER["REMOTE_ADDR"];
}
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joao Daniel |
