Your IPv4: 18.118.126.159
Country: United States
Region: Ohio
City: Dublin
ZIP: 43017
Timezone: America/New_York
Internet Service Provider (ISP): Amazon.com, Inc.
Organization: AWS EC2 (us-east-2)
AS number and name: AS16509 Amazon.com, Inc.
User Agent: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Your IPv6: Not detected
Funcție de interogare API pentru extragerea de informații despre utilizator pe baza adresei IP și User Agent.
functions.php
code:
function get_user_ip() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function show_my_ip_shortcode() {
$user_ip = get_user_ip();
// Cerere către API pentru informații detaliate
$api_url = "http://ip-api.com/json/{$user_ip}";
$response = @file_get_contents($api_url);
$data = json_decode($response, true);
$output = '<div class="ip-info-container">';
$output .= '<h2>Show My IP</h2>';
if ($data && $data['status'] == 'success') {
$output .= "<p><strong>Your IPv4:</strong> " . htmlspecialchars($user_ip) . "</p>";
$output .= "<p><strong>Country:</strong> " . htmlspecialchars($data['country']) . "</p>";
$output .= "<p><strong>Region:</strong> " . htmlspecialchars($data['regionName']) . "</p>";
$output .= "<p><strong>City:</strong> " . htmlspecialchars($data['city']) . "</p>";
$output .= "<p><strong>ZIP:</strong> " . htmlspecialchars($data['zip']) . "</p>";
$output .= "<p><strong>Timezone:</strong> " . htmlspecialchars($data['timezone']) . "</p>";
$output .= "<p><strong>Internet Service Provider (ISP):</strong> " . htmlspecialchars($data['isp']) . "</p>";
$output .= "<p><strong>Organization:</strong> " . htmlspecialchars($data['org']) . "</p>";
$output .= "<p><strong>AS number and name:</strong> " . htmlspecialchars($data['as']) . "</p>";
} else {
$output .= "<p>Could not retrieve IP information. Please try again later.</p>";
}
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$output .= "<p><strong>User Agent:</strong> " . htmlspecialchars($user_agent) . "</p>";
if (filter_var($user_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$output .= "<p><strong>Your IPv6:</strong> " . htmlspecialchars($user_ip) . "</p>";
} else {
$output .= "<p><strong>Your IPv6:</strong> Not detected</p>";
}
$output .= '</div>';
add_action('wp_head', 'ip_info_styles');
return $output;
}
add_shortcode('show_my_ip', 'show_my_ip_shortcode');
function ip_info_styles() {
echo '<style>
.ip-info-container {
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #1C2226;
border-radius: 5px;
background-color: #1B1B1B;
}
.ip-info-container p {
margin: 10px 0;
}
.ip-info-container strong {
color: #F37D31;
}
</style>';
}
add_action('wp_head', 'ip_info_styles');
Shortcode: show_my_ip