Skip to content

Instantly share code, notes, and snippets.

@stenito
stenito / publicip.php
Last active January 21, 2024 03:16
Get public IP address (or wan IP address) with php function
<?php
function getPublicIP() {
// create & initialize a curl session
$curl = curl_init();
// set our url with curl_setopt()
curl_setopt($curl, CURLOPT_URL, "http://httpbin.org/ip");
// return the transfer as a string, also with setopt()