Showing
1 changed file
with
54 additions
and
0 deletions
@@ -1090,4 +1090,58 @@ class Helpers | @@ -1090,4 +1090,58 @@ class Helpers | ||
1090 | { | 1090 | { |
1091 | return preg_match("/[\x7f-\xff]/", $str); | 1091 | return preg_match("/[\x7f-\xff]/", $str); |
1092 | } | 1092 | } |
1093 | + | ||
1094 | + /** | ||
1095 | + * 将首字符为//的url转换为http:// | ||
1096 | + * | ||
1097 | + * @param string $url 需要转换的url | ||
1098 | + * @return mixed | ||
1099 | + */ | ||
1100 | + public static function transHttpsUrl($url) | ||
1101 | + { | ||
1102 | + return preg_replace('/^\/\//', 'http://', $url); | ||
1103 | + } | ||
1104 | + | ||
1105 | + /** | ||
1106 | + * http和https转换成// | ||
1107 | + * @param type $url 地址 | ||
1108 | + * @return type string | ||
1109 | + */ | ||
1110 | + public static function getUrlSafe($url) | ||
1111 | + { | ||
1112 | + if (self::isStrpos(array('/special_', '/special/'), $url)) { | ||
1113 | + return $url; | ||
1114 | + } | ||
1115 | + return strtr($url, array('http://' => '//')); | ||
1116 | + } | ||
1117 | + | ||
1118 | + /** | ||
1119 | + * 查找数组是否包含字符串中 | ||
1120 | + * @param type $array 要查找的数组 | ||
1121 | + * @param type $str 要搜索的字符串 | ||
1122 | + * @return boolean | ||
1123 | + */ | ||
1124 | + public static function isStrpos($array = array(), $str = '') | ||
1125 | + { | ||
1126 | + foreach ($array as $val) { | ||
1127 | + if (strpos($str, $val) !== false) { | ||
1128 | + return true; | ||
1129 | + } | ||
1130 | + } | ||
1131 | + return false; | ||
1132 | + } | ||
1133 | + | ||
1134 | + /** | ||
1135 | + * 获取当前页面是http还是https | ||
1136 | + * @return string | ||
1137 | + */ | ||
1138 | + public static function getHttpOrHttps() { | ||
1139 | + | ||
1140 | + if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || | ||
1141 | + (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] === 443) || | ||
1142 | + (isset($_SERVER['HTTP_REFERER']) && substr($_SERVER['HTTP_REFERER'], 0, 5) === 'https')) { | ||
1143 | + return 'https:'; | ||
1144 | + } | ||
1145 | + return 'http:'; | ||
1146 | + } | ||
1093 | } | 1147 | } |
-
Please register or login to post a comment