|
หัวข้อ: php เช็ค IP จากภายใน และ IP จากภายนอก เริ่มหัวข้อโดย: nyu ที่ 19 กุมภาพันธ์ 2013, 19:46:45 php จะให้เช็ค IP จากภายใน และ IP จากภายนอก ถ้า IP จาก Network ภายใน ก็ให้เข้าให้เข้าใช้งานเว็บได้เว็บ แต่ถ้าเป็น IP ที่มาจาก Network ภายนอก ก็จะให้แสดงบอกแจ้งว่าคุณไม่มีสิทธฺเข้าใช้งานระบบนี้ ประมาณนี้อ่ะ
จะใช้กับระบบ Intranet ครับ หัวข้อ: Re: php เช็ค IP จากภายใน และ IP จากภายนอก เริ่มหัวข้อโดย: HiggsMan ที่ 19 กุมภาพันธ์ 2013, 21:25:23 Here's a simple, quick but effective way to block unwanted external visitors to your local server:
<?php // only local requests if ($_SERVER['REMOTE_ADDR'] !== '127.0.0.1') die(header("Location: /")); ?> This will direct all external traffic to your home page. Of course you could send a 404 or other custom error. Best practice is not to stay on the page with a custom error message as you acknowledge that the page does exist. That's why I redirect unwanted calls to (for example) phpmyadmin. โค๊ด: http://php.net/manual/en/reserved.variables.server.php or <?php if ((substr($_SERVER['REMOTE_ADDR'],0,8) == "192.168.") || ($_SERVER['REMOTE_ADDR'] == "127.0.0.1")) { ... } ?> FYI : http://php.net/manual/en/function.ip2long.php |