รูป database ที่ใช้เก็บค่า ip address ได้ให้เก็บอยู่ในตัวแปร ip ชนิด int ความยาว 11 โดยได้เขียน code ตัวอย่างที่ใช้แสดงผลดังนี้ค่ะ
หน้า ip.php
โค้ด: เลือกทั้งหมด
<?php
$aeip = $fetch['ip'];
echo preg_replace('/\.\d{1,3}\z/', '.***', $aeip);
?>
1. code เมื่อกดปุ่ม Calculate
โค้ด: เลือกทั้งหมด
<button class="btn btn-success" type="submit" id="submit" name="submit" disabled>Calculate</button>
<?php
if (isset($_GET['id'])) {
echo '<input type = "hidden" name = "id" value = "' . $_GET['id'] . '" />';
}
if (isset($_POST['submit'])) {
$ip = $_SERVER["REMOTE_ADDR"];
?>
โค้ด: เลือกทั้งหมด
<tr class="active">
<td align="right" width="50%">
<b><?php echo "หมายเลข IP Address "; ?></b>
</td>
<td>
<?php echo $ip; ?>
</td>
</tr>
โค้ด: เลือกทั้งหมด
<div class="row">
<div class="col-md-12 table-responsive" align="center">
<h3 align="center">ข้อมูลการเข้าใช้งานล่าสุด</h3>
<table class="table table-striped">
<thead class="bg-primary" align="center">
<tr>
<th>
<p align="center">หมายเลข<br>IP Address</p>
</th>
</tr>
</thead>
<?php
$sql = "SELECT * FROM $ชื่อฐานข้อมูล ORDER BY id desc Limit 10";
$result = mysqli_query($con, $sql);
while ($fetch = mysqli_fetch_assoc($result)) {
?>
<tr align="center">
<td>
<?php include 'ip.php'; ?>
</td>
</tr>
<?php
}
?>