Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coppa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Come visualizzare l’indirizzo IP di un utente in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete visualizzare l’indirizzo IP di un utente in WordPress?

Se gli utenti devono conoscere il loro indirizzo IP per configurare uno dei vostri prodotti o completare il vostro tutorial, è utile mostrare loro l’indirizzo IP esatto che devono utilizzare.

In questo articolo vi mostreremo come visualizzare l’indirizzo IP di un utente sul vostro sito web WordPress.

How to display a user's IP address in WordPress

Perché visualizzare l’indirizzo IP di un utente in WordPress?

L’indirizzo IP (Internet Protocol) è una stringa di numeri separati da periodi che viene utilizzata per identificare i dispositivi hardware su una rete. Ciò significa che l’indirizzo IP del visitatore identifica semplicemente il dispositivo che sta utilizzando per connettersi a Internet, come lo smartphone, il computer o il tablet.

Ci sono molti casi in cui i visitatori hanno bisogno di conoscere il proprio indirizzo IP. Ad esempio, a volte gli utenti devono digitare il proprio indirizzo IP quando impostano un software, in particolare i plugin di sicurezza di WordPress come i firewall.

Se vendete questo tipo di software, l’impostazione dell’indirizzo IP univoco dell’utente nella vostra documentazione online aiuterà i vostri clienti a configurare il nuovo software.

Anche se non vendete il software, molti blogger WordPress pubblicano guide utili su come utilizzare software di terze parti. Se state scrivendo un tutorial in cui il lettore deve digitare il proprio indirizzo IP, mostrare l’esatto indirizzo IP da utilizzare può aiutarvi a creare un tutorial migliore.

In questo articolo abbiamo diversi modi per mostrare l’indirizzo IP dell’utente sul vostro sito web WordPress. Se preferite passare direttamente a un metodo particolare, potete utilizzare i colleghi qui sotto.

1. Come visualizzare l’indirizzo IP di un visitatore in WordPress con un plugin

Il modo più semplice per visualizzare l’indirizzo IP di un utente in WordPress è utilizzare il plugin User IP and Location. Si tratta di un semplice plugin che consente di mostrare l’indirizzo IP del visitatore su qualsiasi pagina, articolo o area pronta per il widget utilizzando uno shortcode.

Per prima cosa, è necessario installare e attivare il plugin. Se avete bisogno di aiuto, consultate la nostra guida su come installare un plugin di WordPress.

Una volta attivato, è sufficiente aprire la pagina, l’articolo o l’area pronta per il widget in cui si desidera mostrare l’indirizzo IP del visitatore. Quindi, fare clic sull’icona del blocco aggiuntivo “Più” e cercare “Shortcode”.

Quando appare il blocco giusto, fate clic per aggiungerlo al vostro sito web WordPress.

Showing the visitor's IP address on your WordPress website using a shortcode

Ora è sufficiente digitare lo shortcode [userip_location type=ip]. Per un approfondimento sull’uso degli shortcode, consultate la nostra guida per principianti su come add-onare uno shortcode in WordPress.

Una volta fatto ciò, fai clic sul pulsante “Aggiorna” o “Pubblica” per salvare le modifiche.

Showing a visitor's IP address on your WordPress website

Ora, se visitate questa pagina, vedrete il vostro indirizzo IP univoco.

2. Come visualizzare l’indirizzo IP di un utente in WordPress con il codice

È possibile mostrare l’indirizzo IP di un utente anche aggiungendo del codice al proprio blog o sito web WordPress. Questo codice creerà uno shortcode unico che potrete inserire in qualsiasi punto del vostro sito.

È semplice copiare e incollare del codice nel sito. Tuttavia, è sempre una buona idea creare un backup prima di apportare modifiche al codice del sito web.

Se non state ancora eseguendo il backup del vostro sito web WordPress, potete consultare la nostra selezione di esperti dei migliori plugin per il backup di WordPress.

Per mostrare l’indirizzo IP dell’utente, aprire il file functions.php del tema, creare un plugin specifico per il sito o utilizzare un plugin code snippets.

Indipendentemente dall’opzione scelta, è sufficiente incollare il seguente codice:

function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return apply_filters( 'wpb_get_ip', $ip );
}
 
add_shortcode('show_ip', 'get_the_user_ip');

Dopo aver fatto ciò, attivate il plugin specifico per il sito, salvate il vostro frammento di codice o salvate le modifiche apportate al file functions.php del vostro sito.

Ora è stato creato uno shortcode [show_ip] che può essere utilizzato per mostrare l’indirizzo IP del visitatore su qualsiasi pagina, articolo o area pronta per il widget.

Per una guida passo passo su come add-on lo shortcode, consultare la nostra guida per principianti su come aggiungere uno shortcode in WordPress.

Speriamo che questo articolo vi abbia aiutato a imparare come visualizzare l’indirizzo IP di un utente nel vostro sito WordPress. Potreste anche voler selezionare la nostra guida su come consentire la registrazione degli utenti sul vostro sito WordPress e il miglior software di live chat per le piccole imprese.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

25 commentiLascia una risposta

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

    • WPBeginner Support says

      That would require some advanced php or a plugin, we don’t have a recommended method at the moment.

      Admin

  2. Lathif says

    unfortunately there is still a weakness of the function, that is the problem of “cache”.
    visitors will see the same ip address (even if the router is restarted) when they are not clearing “cache” in the browser.

  3. Beatriz says

    Where can I see the IP’s collected? and should I paste the snippet of the code on the top of my function.php code?

  4. Brigitte Scherieble says

    hey,
    I am from Germany and I am not a computer freak. But I have the job to find out of the client IP (out of Google Analytics) the Company of the visiter. Can you help me?

  5. Evan says

    This works great, thank you! Is there any way to have it also display the hostname, perhaps with a separate shortcode?

  6. Reuben Tinto says

    Hi,

    Is it possible to obtain the IP of a previous blog visitor trough this method? If not are you aware of any other courses of action I can take?

    Also will I be able to access code if I do not have a premium wordpress account?
    I have been trying to locate the IP of an anonymous twitter troll and would really appreciate some help! :)

    Reuben

  7. Mike says

    Thanks for the tutorial. Please excuse if this is a dumb question but I’m new to working with WordPress.

    If I want to store the visitors IP address along with the date and time they visited a post, should I create a separate mysql database table or is there an existing wp table that collects this information that I can retrieve?

    • Mohammad Mursaleen says

      Creating a table for such functionality in WordPress is not an efficient move. I would prefer to do this using custom post type.

      I have answered a similar question over here;

  8. Pippin Williamson says

    It should probably be noted that $_SERVER[‘REMOTE_ADDR’] will not always retrieve the IP properly.

    If the user is on a shared connection, you will need to use $_SERVER[‘HTTP_X_FORWARDED_FOR’].

    If the user is behind a proxy, you will need to use $_SERVER[‘HTTP_X_FORWARDED_FOR’].

    The IP can also be present in $_SERVER[‘HTTP_CLIENT_IP’].

    To properly get the IP reliably, something like this should be used:

    function get_the_user_ip() {
    if ( ! empty( $_SERVER[‘HTTP_CLIENT_IP’] ) ) {
    //check ip from share internet
    $ip = $_SERVER[‘HTTP_CLIENT_IP’];
    } elseif ( ! empty( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) {
    //to check ip is pass from proxy
    $ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
    } else {
    $ip = $_SERVER[‘REMOTE_ADDR’];
    }
    return apply_filters( ‘edd_get_ip’, $ip );
    }

  9. Chris Black says

    Always worth noting that although you can read the IP address with PHP that it may not be useful because people have shared IP addresses, dynamic IP, access websites from different networks/locations and because it is possible to fake the IP address that PHP sees. So – only use an IP address with caution.

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.