3v4l.org

run code in 300+ PHP versions simultaneously
<?php // simple example $bcast = ip2long("192.168.178.255"); $smask = ip2long("255.255.255.0"); $nmask = $bcast & $smask; echo long2ip($nmask); // Will give 192.168.178.0 ?> With this example you are able to check if a given host is in your own local net or not (on linux): <?php /** * Check if a client IP is in our Server subnet * * @param string $client_ip * @param string $server_ip * @return boolean */ function clientInSameSubnet($client_ip=false,$server_ip=false) { if (!$client_ip) $client_ip = $_SERVER['REMOTE_ADDR']; if (!$server_ip) $server_ip = $_SERVER['SERVER_ADDR']; // Extract broadcast and netmask from ifconfig if (!($p = popen("ifconfig","r"))) return false; $out = ""; while(!feof($p)) $out .= fread($p,1024); fclose($p); // This is because the php.net comment function does not // allow long lines. $match = "/^.*".$server_ip; $match .= ".*Bcast:(\d{1,3}\.\d{1,3}i\.\d{1,3}\.\d{1,3}).*"; $match .= "Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/im"; if (!preg_match($match,$out,$regs)) return false; $bcast = ip2long($regs[1]); $smask = ip2long($regs[2]); $ipadr = ip2long($client_ip); $nmask = $bcast & $smask; return (($ipadr & $smask) == ($nmask & $smask)); } ?>
Output for git.master, git.master_jit, rfc.property-hooks
192.168.178.0 With this example you are able to check if a given host is in your own local net or not (on linux):

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
42.89 ms | 401 KiB | 8 Q