Changeset 580 for trunk/lib/Utilities.inc.php
- Timestamp:
- Feb 27, 2017 2:23:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r560 r580 809 809 * Converts a PHP Array into encoded URL arguments and return them in a string. 810 810 * 811 * Todo: probably update to use the built-in http_build_query(). 812 * 811 813 * @param mixed $data An array to transverse recursively, or a string 812 814 * to use directly to create url arguments. … … 1059 1061 break; 1060 1062 } 1063 } 1064 1065 /* 1066 * Generates a base-65-encoded sha512 hash of $string truncated to $length. 1067 * 1068 * @access public 1069 * @param string $string Input string to hash. 1070 * @param int $length Length of output hash string. 1071 * @return string String of hash. 1072 * @author Quinn Comendant <quinn@strangecode.com> 1073 * @version 1.0 1074 * @since 03 Apr 2016 19:48:49 1075 */ 1076 function hash64($string, $length=18) 1077 { 1078 return mb_substr(preg_replace('/[^\w]/', '', base64_encode(hash('sha512', $string, true))), 0, $length); 1061 1079 } 1062 1080 … … 1375 1393 function refererIsMe($exclude_query=false) 1376 1394 { 1395 $current_url = absoluteMe(); 1396 $referer_url = getenv('HTTP_REFERER'); 1397 1398 // If one of the hostnames is an IP address, compare only the path of both. 1399 if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($current_url, PHP_URL_HOST)) || preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($referrer_url, PHP_URL_HOST))) { 1400 $current_url = preg_replace('@^https?://[^/]+@', '', $current_url); 1401 $referer_url = preg_replace('@^https?://[^/]+@', '', $referer_url); 1402 } 1403 1377 1404 if ($exclude_query) { 1378 return (stripQuery(absoluteMe()) == stripQuery(getenv('HTTP_REFERER'))); 1379 } else { 1380 return (absoluteMe() == getenv('HTTP_REFERER')); 1405 return (stripQuery($current_url) == stripQuery($referer_url)); 1406 } else { 1407 $app =& App::getInstance(); 1408 $app->logMsg(sprintf('refererIsMe comparison: %s == %s', $current_url, $referer_url), LOG_DEBUG, __FILE__, __LINE__); 1409 return ($current_url == $referer_url); 1381 1410 } 1382 1411 } … … 1395 1424 { 1396 1425 $ch = curl_init($url); 1426 curl_setopt($ch, CURLOPT_TIMEOUT, 2); 1397 1427 curl_setopt($ch, CURLOPT_NOBODY, true); 1398 1428 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Note: See TracChangeset
for help on using the changeset viewer.