Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ip = '192.168.1.5';
- $ips = [
- '192.168.1.3',
- '192.168.1.4',
- '192.168.1.5',
- ];
- foreach ($ips as $i) {
- if ($ip === $i) {
- goto allowed;
- }
- }
- throw new Exception('Not allowed');
- allowed:
- ...
- $allowed = false;
- foreach ($ips as $i) {
- if ($ip === $i) {
- $allowed = true;
- break;
- }
- }
- if (!$allowed) {
- throw new Exception('Not allowed');
- }
- if (!in_array($ip, $ips)) throw new Exception('Not allowed');
- if (!contains($ips, $ip)) throw new Exception('Not allowed');
- $list_contains_ip = undef; # STATE: we don't know yet
- foreach ($ips as $i) {
- if ($ip === $i) {
- $list_contains_ip = true; # STATE: positive
- break;
- }
- # STATE: we still don't know yet, huh?
- }
- # Well, then...
- $list_contains_ip = false; # STATE: negative
- if (!$list_contains_ip) {
- throw new Exception('Not allowed');
- }
- # STATE: unknown
- foreach ($ips as $i) { # What are we checking here anyway?
- if ($ip === $i) {
- goto allowed; # STATE: positive
- }
- # STATE: unknown
- }
- # guess this means STATE: negative
- throw new Exception('Not allowed');
- allowed: # Guess we jumped over the trap door
- if ($ip =~ /:/) goto IP_V6;
- if ($ip =~ ///) goto IP_RANGE;
- if ($ip =~ /^10./) goto IP_IS_PRIVATE;
- foreach ($ips as $i) { ... }
- IP_IS_PRIVATE:
- foreach ($ip_priv as $i) { ... }
- IP_V6:
- foreach ($ipv6 as $i) { ... }
- IP_RANGE:
- # i don't even want to know how you'd implement that
- ALLOWED:
- # Wait, is this code even correct?
- # There seems to be a bug in here.
- func foo(){
- foreach ($ips as $i) {
- if ($ip === $i) {
- return;
- }
- }
- throw new Exception('Not allowed');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement