2 Star 33 Fork 11

冰优 / iceCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
demo.html 4.18 KB
一键复制 编辑 原始数据 按行查看 历史
冰优 提交于 2020-11-20 14:54 . 优化样式的权重
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<link type="text/css" rel="stylesheet" href="src/iceCode.css">
<script src="src/iceCode.js"></script>
<title>iceCode-代码高亮演示DEMO</title>
</head>
<body>
<pre class="iceCode:php">
/**
+------------------------------------------------------------------------------------+
+ 功能:获取用户真实IP
+ 网址:https://www.uzjz.com
+------------------------------------------------------------------------------------+
+ @return string
+------------------------------------------------------------------------------------+
*/
function ip(){
static $realip;
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$realip = isset($_SERVER['HTTP_CLIENT_IP'])?$_SERVER['HTTP_CLIENT_IP']:$_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$realip = getenv('HTTP_X_FORWARDED_FOR');
} else {
$realip = getenv('HTTP_CLIENT_IP')?getenv('HTTP_CLIENT_IP'):getenv('REMOTE_ADDR');
}
}
return $realip;
}
/**
+------------------------------------------------------------------------------------+
+ 功能:通过一个 HTTPS POST 请求获取内容
+------------------------------------------------------------------------------------+
+ @param $url {string} 完整的网址
+ @param $post {string} POST 内容,格式:username=Jack&password=123465
+ @param $cookie {string} COOKIE 数据,格式:username=Jack&password=123456
+ @param $timeout {int} 请求超时
+ @param $times {int} 重试次数
+ @return string
+------------------------------------------------------------------------------------+
*/
function postHttps($url, $post = '', $cookie = '', $timeout = 30, $times = 1, $method = 'POST') {
if(substr($url, 0, 7) == 'http://') return postHttp($url, $post, $cookie, $timeout, $times);
is_array($post) AND $post = http_build_query($post);
is_array($cookie) AND $cookie = http_build_query($cookie);
$w = stream_get_wrappers();
$allow_url_fopen = strtolower(ini_get('allow_url_fopen'));
$allow_url_fopen = (empty($allow_url_fopen) || $allow_url_fopen == 'off') ? 0 : 1;
if (!function_exists('curl_init')) {
return message(-1, 'server not installed curl.');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 2); // 1/2
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded', 'x-requested-with: XMLHttpRequest'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, _SERVER('HTTP_USER_AGENT'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在,默认可以省略
if($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$header = array('Content-type: application/x-www-form-urlencoded', 'X-Requested-With: XMLHttpRequest');
if($cookie) {
$header[] = "Cookie: $cookie";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
(!ini_get('safe_mode') && !ini_get('open_basedir')) && curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转, 安全模式不允许
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
if(curl_errno($ch)) {
return message(-1, 'Errno'.curl_error($ch));
}
if(!$data) {
curl_close($ch);
return '';
}
list($header, $data) = explode("\r\n\r\n", $data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 301 || $http_code == 302) {
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
}
curl_close($ch);
return $data;
}
</pre>
<script>ice.code.light();</script>
</body>
</html>
JavaScript
1
https://gitee.com/iceui/iceCode.git
git@gitee.com:iceui/iceCode.git
iceui
iceCode
iceCode
master

搜索帮助