User Location and IP details Info Box

Spartak

Well-known member
Member
Joined
9 yrs. 9 mth. 5 days
Messages
587
Reaction score
8,878
Wallet
0$
User Location and IP details Info Box

Heya Guys!<br />
This is my first tutorial so just don't judge me please.<br />
Recently I started learning php and made some small codes to work with mybb.So here I will share you the tutorial of a side box where user can see his IP and it's basic details like location, country code, timezone, currency, region etc.Something like this:<br />
<br />
Please, Log in or Register to view URLs content!
<img src="
Please, Log in or Register to view URLs content!
" data-original-url="https://i.ibb.co/F8sTPDQ/User-Info-Display-box.png" loading="lazy" alt="[Image: User-Info-Display-box.png]" class="mycode_img" /><br />
<br />
<br />
So first of all go to you index.php file and add this code before "&#36;plugins-&gt;run_hooks('index_end');"<br />
<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-php">function getUserIP()
{
    // Get real visitor IP behind CloudFlare network
    if (isset($_SERVER[&quot;HTTP_CF_CONNECTING_IP&quot;])) {
              $_SERVER['REMOTE_ADDR'] = $_SERVER[&quot;HTTP_CF_CONNECTING_IP&quot;];
              $_SERVER['HTTP_CLIENT_IP'] = $_SERVER[&quot;HTTP_CF_CONNECTING_IP&quot;];
    }
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}


$ip = getUserIP();

$ch = curl_init('
Please, Log in or Register to view URLs content!

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);

// Decode JSON response
$ipwhois_result = json_decode($json, true);

// Country code output, field &quot;country_code&quot;
$cc = $ipwhois_result['country_code'];
$isp = $ipwhois_result['isp'];
$tz = $ipwhois_result['timezone'];
$money = $ipwhois_result['currency'];
$region = $ipwhois_result['region'];
$city = $ipwhois_result['city'];</code></pre><br />
<br />
<br />
Now Go to acp &gt; template and style &gt; index template and add this code wherever you want this box to be displayed:<br />
<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; class=&quot;tborder&quot; style=&quot;width: 100%; float: right; margin-bottom: 10px;&quot;&gt;
    &lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&quot;thead&quot; colspan=&quot;5&quot; width=&quot;100%&quot; style=&quot;background: #47CB14; color: #fff; background-image: url(
Please, Log in or Register to view URLs content!
background-size: cover;&quot;&gt;
&lt;span style=&quot;padding: 4px 10px; background: rgba(0,0,0,0.13); border-radius: 2px;&quot;&gt;
    &lt;strong&gt;Your Info&lt;/strong&gt;
&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-server&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your IP:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$ip}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-globe-africa&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your Country Code:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$cc}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-user-clock&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your Timezone:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$tz}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-server&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your Region:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$region}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-city&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your City:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$city}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;&lt;i class=&quot;fas fa-money-bill-wave&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;&amp;nbsp; Your Currency:&lt;/font&gt;&lt;/td&gt;
&lt;td class=&quot;trow1&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;white&quot;&gt;{$money}&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</code></pre><br />
And You are done!!! Please reply for any suggestions or queries!!<br />
<br />
Warm Regards,<br />
Venom <img src="
Please, Log in or Register to view URLs content!
" alt="Big Grin" title="Big Grin" class="smilie smilie_5" />


Please, Log in or Register to view URLs content!
 
Top Bottom