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 />
<img src=" " 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 "$plugins->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["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$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('
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 "country_code"
$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 > template and style > 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"><table border="0" cellspacing="0" cellpadding="5" class="tborder" style="width: 100%; float: right; margin-bottom: 10px;">
<tbody>
<tr>
<td class="thead" colspan="5" width="100%" style="background: #47CB14; color: #fff; background-image: url( background-size: cover;">
<span style="padding: 4px 10px; background: rgba(0,0,0,0.13); border-radius: 2px;">
<strong>Your Info</strong>
</span></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-server" aria-hidden="true"></i>&nbsp; Your IP:</font></td>
<td class="trow1" width="100%"><font color="white">{$ip}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-globe-africa" aria-hidden="true"></i>&nbsp; Your Country Code:</font></td>
<td class="trow1" width="100%"><font color="white">{$cc}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-user-clock" aria-hidden="true"></i>&nbsp; Your Timezone:</font></td>
<td class="trow1" width="100%"><font color="white">{$tz}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-server" aria-hidden="true"></i>&nbsp; Your Region:</font></td>
<td class="trow1" width="100%"><font color="white">{$region}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-city" aria-hidden="true"></i>&nbsp; Your City:</font></td>
<td class="trow1" width="100%"><font color="white">{$city}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-money-bill-wave" aria-hidden="true"></i>&nbsp; Your Currency:</font></td>
<td class="trow1" width="100%"><font color="white">{$money}</font></td>
</tr>
</tbody>
</table></code></pre><br />
And You are done!!! Please reply for any suggestions or queries!!<br />
<br />
Warm Regards,<br />
Venom <img src=" " alt="Big Grin" title="Big Grin" class="smilie smilie_5" />
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 />
<img src=" " 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 "$plugins->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["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$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('
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 "country_code"
$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 > template and style > 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"><table border="0" cellspacing="0" cellpadding="5" class="tborder" style="width: 100%; float: right; margin-bottom: 10px;">
<tbody>
<tr>
<td class="thead" colspan="5" width="100%" style="background: #47CB14; color: #fff; background-image: url( background-size: cover;">
<span style="padding: 4px 10px; background: rgba(0,0,0,0.13); border-radius: 2px;">
<strong>Your Info</strong>
</span></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-server" aria-hidden="true"></i>&nbsp; Your IP:</font></td>
<td class="trow1" width="100%"><font color="white">{$ip}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-globe-africa" aria-hidden="true"></i>&nbsp; Your Country Code:</font></td>
<td class="trow1" width="100%"><font color="white">{$cc}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-user-clock" aria-hidden="true"></i>&nbsp; Your Timezone:</font></td>
<td class="trow1" width="100%"><font color="white">{$tz}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-server" aria-hidden="true"></i>&nbsp; Your Region:</font></td>
<td class="trow1" width="100%"><font color="white">{$region}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-city" aria-hidden="true"></i>&nbsp; Your City:</font></td>
<td class="trow1" width="100%"><font color="white">{$city}</font></td>
</tr>
<tr>
<td class="trow1" width="100%"><font color="white"><i class="fas fa-money-bill-wave" aria-hidden="true"></i>&nbsp; Your Currency:</font></td>
<td class="trow1" width="100%"><font color="white">{$money}</font></td>
</tr>
</tbody>
</table></code></pre><br />
And You are done!!! Please reply for any suggestions or queries!!<br />
<br />
Warm Regards,<br />
Venom <img src=" " alt="Big Grin" title="Big Grin" class="smilie smilie_5" />