- preg_match: documentation ( source)
<?php
$url ="[::1]/challenges/flag.php";
if (preg_match ('/[https?|[st]?ftp|dict|gopher|scp|telnet|ldaps?]\:\/\/.*(\d+|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/i', $url)) {
die('Please do not access by IP.');
} elseif (preg_match ('/localhost/i', $url)) {
die ('Please do not access localhost.');
}