Guest User

Untitled

a guest
Jun 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2. function url_parts($local, $global)
  3. {
  4. global $boardurl;
  5.  
  6. // Parse the URL with PHP to make life easier.
  7.  
  8. $parsed_url = parse_url($boardurl);
  9.  
  10. // Is local cookies off?
  11.  
  12. if (empty($parsed_url['path']) || !$local) $parsed_url['path'] = '';
  13.  
  14. // Globalize cookies across domains (filter out IP-addresses)?
  15.  
  16. if ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 &&
  17. preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) ==
  18. 1) $parsed_url['host'] = '.' . $parts[1];
  19.  
  20. // We shouldn't use a host at all if both options are off.
  21.  
  22. elseif (!$local && !$global) $parsed_url['host'] = '';
  23.  
  24. // The host also shouldn't be set if there aren't any dots in it.
  25.  
  26. elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
  27. $parsed_url['host'] = '';
  28.  
  29. return array($parsed_url['host'], $parsed_url['path'] . '/');
  30. }
Add Comment
Please, Sign In to add comment