标签 php 下的文章

PHP判断搜索引擎蜘蛛来路进行301跳转

<?php
if (preg_match("#(Baiduspider|Googlebot|Sogou spider|Sogou web spider|Sogou wap spider|YodaoBot|YandexBot|bingbot|Yahoo! Slurp|MSNBot|Bytespider|YisouSpider|360Spider|Yahoo)#si", $_SERVER['HTTP_USER_AGENT'])) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: https://www.2dan.cc/");
    exit;
}
?>

用户访问网站完全正常,搜索引擎蜘蛛 User Agent 就301跳转。这个不得不说很隐蔽,被搞了不容易发现。

PHP天数计算

<?PHP
//今天与2012年11月29日相差多少天
$Date_1=date("Y-m-d");
$Date_2="2012-11-29";
$d1=strtotime($Date_1);
$d2=strtotime($Date_2);
$Days=round(($d1-$d2)/3600/24);
Echo "宝宝出生已经".$Days."天";
Echo "<br>";

//今天到2013年11月29日还有多少天
$Date_1=date("Y-m-d");
$Date_2="2013-11-29";
$d1=strtotime($Date_1);
$d2=strtotime($Date_2);
$Days=round(($d2-$d1)/3600/24);
Echo "离宝宝生日还有".$Days."天";

?>

ini_set(

今天在查看messages日志文件时,发现存在大量的错误:

Jan  4 14:41:08 myhost suhosin[954]: ALERT - script tried to disable memory_limit by setting it to a negative value -1 bytes which is not allowed (attacker '110.75.173.*', file '/home/wwwroot/2dan.cc/index.php', line 5)

后来发现原因是:index.php文件中有这么一行:

// 取消内存限制
ini_set("memory_limit",'-1');

而php.ini中

memory_limit = 128M

解决方法:

  1. 删除index.php中的ini_set("memory_limit",'-1');
  2. 将二处的值改为相同。
  3. 卸载suhosin
  4. 修改php.ini中的memory_limit = -1

不推荐4,原因是可能内存会被吃光。

安装vnstat PHP frontend以实现对vnstat的web管理

之前介绍了Vnstat的安装和基本使用,为了更直观和方便的显示流量统计信息,我们采用vnstat PHP frontend

wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
tar xvf vnstat_php_frontend-1.5.1.tar.gz
mv vnstat_php_frontend-1.5.1 vnstat
cd vnstat/

修改config.php,将里面的内容修改成如下:
语言显示:

$locale = ‘en_US.UTF-8′;
$language = ‘en’;

网卡接口:

$iface_list = array(‘eth0′);

如果有多个网卡接口,要修改成类似如下:

$iface_list = array(‘eth0′, ‘eth1′);

- 阅读剩余部分 -