在common.php里,有这么一段代码
//启用GIP
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
如果服务器支持gzip的话,那么就调用
ob_start('ob_gzhandler');
ob_start的意思是开始数据缓冲,也就是服务器的echo的东西会放在缓冲区里不会直接发送给浏览器。ob_gzhandler是作为回调函数来调用的。关于此函数解释为
ob_gzhandler()
is intended to be
used as a callback
function for ob_start()
to help facilitate sending
gz-encoded data to web browsers that support compressed web pages.
Before ob_gzhandler()
actually
sends compressed data,
it determines what type of content encoding the browser will accept
("gzip", "deflate" or none at all) and will return its output
accordingly.
All browsers are supported since it's up to the browser to send the
correct header saying that it accepts compressed web pages. If a
browser
doesn't support compressed pages this function returns FALSE
.
而ob_start的那个callback参数的解释如下
When
output_callback
is called, it
will receive the
contents of the output buffer as its parameter and is expected to
return a new output buffer as a result, which will be sent to the
browser.
也即使说支持gzip的服务器会在把数据传到浏览器之前先把数据传给那个回调函数产生新的输出。ob_gzhandler一定就是压缩数据的方法了。
在function_common里有这么一个函数
ob_out
//调整输出
function ob_out() {
global $_SGLOBAL, $_SCONFIG, $_SC;
$content = ob_get_contents();
$preg_searchs = $preg_replaces = $str_searchs = $str_replaces = array();
if($_SCONFIG['allowrewrite']) {
$preg_searchs[] = "/\<a href\=\"space\.php\?(uid|do)+\=([a-z0-9\=\&]+?)\"/ie";
$preg_searchs[] = "/\<a href\=\"space.php\"/i";
$preg_searchs[] = "/\<a href\=\"network\.php\?ac\=([a-z0-9\=\&]+?)\"/ie";
$preg_searchs[] = "/\<a href\=\"network.php\"/i";
$preg_replaces[] = 'rewrite_url(\'space-\',\'\\2\')';
$preg_replaces[] = '<a href="space.html"';
$preg_replaces[] = 'rewrite_url(\'network-\',\'\\1\')';
$preg_replaces[] = '<a href="network.html"';
}
if($_SCONFIG['linkguide']) {
$preg_searchs[] = "/\<a href\=\"http\:\/\/(.+?)\"/ie";
$preg_replaces[] = 'iframe_url(\'\\1\')';
}
if($_SGLOBAL['inajax']) {
$preg_searchs[] = "/([\x01-\x09\x0b-\x0c\x0e-\x1f])+/";
$preg_replaces[] = ' ';
$str_searchs[] = ']]>';
$str_replaces[] = ']]>';
}
if($preg_searchs) {
$content = preg_replace($preg_searchs, $preg_replaces, $content);
}
if($str_searchs) {
$content = trim(str_replace($str_searchs, $str_replaces, $content));
}
obclean();
if($_SGLOBAL['inajax']) {
xml_out($content);
} else{
if($_SCONFIG['headercharset']) {
@header('Content-Type: text/html; charset='.$_SC['charset']);
}
echo $content;
if(D_BUG) {
@include_once(S_ROOT.'./source/inc_debug.php');
}
}
}
$content = ob_get_contents()为取得缓冲区的内容,在obclean之前都是在做字符串的替换,具体的我也不清楚是怎么搞的。
调用ob_clean()把缓冲区里的数据清楚掉。
如果是ajax请求,那么就返回一个数据的xml形式。
其余情况则很正常地把结果echo出去。你会发现在每一个daat下的tpl缓存页面文件里都有一个ob_out()函数。
贴一下相关函数的代码
function obclean() {
global $_SC;
ob_end_clean();
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
}
function xml_out($content) {
global $_SC;
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
@header("Content-type: application/xml; charset=$_SC[charset]");
echo '<'."?xml version=\"1.0\" encoding=\"$_SC[charset]\"?>\n";
echo "<root><![CDATA[".trim($content)."]]></root>";
exit();
}
2、sstripslashes
//去掉slassh
function sstripslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = sstripslashes($val);
}
} else {
$string = stripslashes($string);
}
return $string;
}
这里就是递归地将数组里的字符串反转义,也就是原来是123\'123的现在变成123'123
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com