Tag Archives: PHP

WordPress设置代理

Leave a comment

WordPress因为各种原因放在国内服务器上经常无法远程更新、安装插件。通过下面方法设置代理就可以了。

/* 配置代理 */
define('WP_PROXY_HOST', '127.0.0.1');//代理服务器
define('WP_PROXY_PORT', '8118');//代理端口
define('WP_PROXY_USERNAME', '');//代理用户名
define('WP_PROXY_PASSWORD', '');//代理密码
define('WP_PROXY_BYPASS_HOSTS', 'localhost');//排除域名

[PHP]DirectAdmin PHP5.6安装swoole

Leave a comment

客户要求安装swoole,也不知道什么鬼用途。记一下笔记。

yum install gcc make autoconf pcre -y
cd ~
wget http://pecl.php.net/get/swoole-1.10.5.tgz
tar -zxvf swoole-1.10.5.tgz
cd swoole-1.10.5
export PHP_PREFIX="/usr/local"
$PHP_PREFIX/php56/bin/phpize
./configure --with-php-config=$PHP_PREFIX/php56/bin/php-config
make -j 2
make install

echo "extension=swoole.so" >> /usr/local/php56/lib/php.conf.d/20-custom.ini
service httpd restart
php -i | grep "swoole"

[PHP]根据User Agent判断是否搜索引擎蜘蛛

Leave a comment
/* 判断搜索引擎 摘自Discuz x3.2 */
function checkrobot($useragent=''){
  static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
  static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');

  $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
  if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
  if(dstrpos($useragent, $kw_spiders)) return true;
  return false;
}
function dstrpos($string, $arr, $returnvalue = false) {
  if(empty($string)) return false;
  foreach((array)$arr as $v) {
    if(strpos($string, $v) !== false) {
      $return = $returnvalue ? $v : true;
      return $return;
    }
  }
  return false;
}

Continue reading

[PHP]PHP获取服务器IP输出为数组

Leave a comment

用PHP执行ifconfig获得Linux服务器IP并输出为数组,下面是代码:

function getServerIp(){ //用ifconfig读取服务器IP并输出为数组
		$ss = exec('/sbin/ifconfig | sed -n \'s/^ *.*addr:\\([0-9.]\\{7,\\}\\) .*$/\\1/p\'',$arr);
		return $arr; 
		}
$ips=getServerIp();
foreach($ips as $k=>$v){//过滤IP
	if(substr($v,0,3)=='127' || substr($v,0,3)=='10.' || substr($v,0,7)=='192.168' || substr($v,0,6)=='172.16'){
		unset($ips[$k]);
	}
}
shuffle($ips);//重新排序
print_r($ips);