1 Star 0 Fork 0

易小猫/spiders

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
common.php 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
易小猫 提交于 2016-09-18 15:33 . initlize commit
<?php
header("Content-type:text/html;charset:utf-8");
/*获取当前访问用户IP*/
function GetIP()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
$ip = getenv("HTTP_CLIENT_IP");
} else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
$ip = getenv("REMOTE_ADDR");
} else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = "unknown";
}
return ($ip);
}
/*格式化header*/
function parseHeaders($headers)
{
$head = array();
foreach ($headers as $k => $v) {
$t = explode(':', $v, 2);
if (isset($t[1])) {
$head[trim($t[0])] = trim($t[1]);
} else {
$head[] = $v;
if (preg_match('/HTTP\/[0-9\.]+\s+([0-9]+)/', $v, $out)) {
$head['reponse_code'] = intval($out[1]);
}
}
}
return $head;
}
/*数组格式化输出header*/
function dumpout($vars, $label = '', $return = false)
{
if (!isset($vars)) return false;
$vars = parseHeaders($vars);
if (ini_get('html_errors')) {
$content = "<pre>\n";
if ($label != '') {
$content .= "<strong>{$label} :</strong>\n";
}
$content .= htmlspecialchars(print_r($vars, true));
$content .= "\n</pre>\n";
} else {
$content = $label . " :\n" . print_r($vars, true);
}
if ($return) {
return $content;
}
echo $content;
return null;
}
/*数组格式化输出arr*/
function dumpArr($vars, $label = '', $return = false)
{
if (ini_get('html_errors')) {
$content = "<pre>\n";
if ($label != '') {
$content .= "<strong>{$label} :</strong>\n";
}
$content .= htmlspecialchars(print_r($vars, true));
$content .= "\n</pre>\n";
} else {
$content = $label . " :\n" . print_r($vars, true);
}
if ($return) {
return $content;
}
echo $content;
return null;
}
/**
* @return string:返回当前主机
* 返回当前主机http:// /形式
*/
function getHost()
{
$host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : 'localhost';
return 'http://' . $host . '/';
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/ecat/spiders.git
git@gitee.com:ecat/spiders.git
ecat
spiders
spiders
master

搜索帮助