discuz 附件过多导致超出数据库的修复

今天一个朋友的discuz论坛上传图片出现无法上传情况,经过chrome F12 调试发现是数据库的附件表的aid超出了MEDIUMINT(8)的允许最大值,所以适当增大就好了,下面的sql有效

ALTER TABLE  `pre_forum_attachment` CHANGE  `aid`  `aid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE  `pre_forum_attachment_unused` CHANGE  `aid`  `aid` BIGINT UNSIGNED NOT NULL;
ALTER TABLE  `pre_forum_attachment_0` CHANGE  `aid`  `aid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
。
。
。
ALTER TABLE  `pre_forum_attachment_9` CHANGE  `aid`  `aid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;

php5.3 zendguard 的一段代码备忘,来自wdcp

zendguard-php5.3

#!/bin/bash
F="ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz"
Aurl="http://dl.wdlinux.cn:5180/soft/"
if [[ `uname -m` == "x86_64" ]];then
        F="ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz"
fi
if [ ! -f $F ];then
        wget -c $Aurl/$F
fi
tar zxvf $F
[ $? != 0 ] && echo "file err" && exit
if [ ! -d /www/wdlinux/Zend/lib ];then
        mkdir -p /www/wdlinux/Zend/lib
fi
if [[ `uname -m` == "x86_64" ]];then
        cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/*.so /www/wdlinux/Zend/lib/
else
        cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/*.so /www/wdlinux/Zend/lib/
fi
grep '\[Zend\]' /www/wdlinux/apache_php/etc/php.ini
if [ $? != 0 -a -f /www/wdlinux/apache_php/etc/php.ini ];then
echo '[Zend]
zend_extension = /www/wdlinux/Zend/lib/ZendGuardLoader.so
zend_loader.enable = 1' >> /www/wdlinux/apache_php/etc/php.ini
fi
grep '\[Zend\]' /www/wdlinux/nginx_php/etc/php.ini
if [ $? != 0 -a -f /www/wdlinux/nginx_php/etc/php.ini ];then
echo '[Zend]
zend_extension = /www/wdlinux/Zend/lib/ZendGuardLoader.so
zend_loader.enable = 1' >> /www/wdlinux/nginx_php/etc/php.ini
fi
echo
echo "ZendGuardLoader is OK"

linux redhat centos 双网卡单网关或者双网关的配置

vim /etc/iproute2/rt_tables 增加
252  cnc
251  tel

在 /etc/rc.local 里面增加

ip route flush table tel
ip route add default via 网关1 dev eth1 src IP1 table tel
ip rule add from IP1 table tel
ip route flush table cnc
ip route add default via 网关2 dev eth0 src IP2 table cnc
ip rule add from IP2 table cnc

注意红色部分即可

写成shell脚本如下

#!/bin/bash

ip1=”1.1.1.2″
e1=”eth0″
gw1=”1.1.1.1″
ip2=”2.2.2.2″
e2=”eth1″
gw2=”2.2.2.1″

#################################################
### 上面的配置要改改
### 下面就不要动了
#################################################

rt=”/etc/iproute2/rt_tables”
echo “252 cnc ” >> $rt
echo “251 tel ” >> $rt
rclocal=”/etc/rc.local”

echo “ip route flush table tel” >> $rclocal
echo “ip route add default via $gw1 dev $e1 src $ip1 table tel” >> $rclocal
echo “ip rule add from $ip1 table tel” >> $rclocal
echo “ip route flush table cnc” >> $rclocal
echo “ip route add default via $gw2 dev $e2 src $ip2 table cnc” >> $rclocal
echo “ip rule add from $ip2 table cnc” >> $rclocal

点此下载

2iprule

php的 uc_client.php 测试一列

define('UC_CONNECT', 'mysql');

define('UC_DBHOST', 'localhost');
define('UC_DBUSER', 'root');
define('UC_DBPW', '');
define('UC_DBNAME', 'ultrax');
define('UC_DBCHARSET', 'utf8');
define('UC_DBTABLEPRE', '`ultrax`.pre_ucenter_');
define('UC_DBCONNECT', 0);

define('UC_CHARSET', 'utf-8');
define('UC_KEY', 'M1K6F1X3Qaj5d103O8J8Labay219occ7w78d5asbb34aZfGbV2O9t9E5m288NfNd');
define('UC_API', 'http://127.0.0.1/dz/uc_server');
define('UC_APPID', '1');
define('UC_IP', '');
define('UC_PPP', 20);

if($_POST)
{

include "uc_client/client.php";
$username=$_POST["u"];
$password=$_POST["p"];
$f = uc_get_user($username, 0);
if(!$f)
{

uc_user_register($username, $password, $username."@aaa.com");
$f = uc_get_user($username, 0);
}
echo uc_user_synlogin($f[0]) ;
}

禁止 某些可写目录执行 php的方法

首先说下分析为啥这个是正确的,
httpd.conf里面 AddType application/x-httpd-php5 .php
并不区分大小写,从而导致 .php .PHP .Php .pHp .phP 都可以正确执行,那么就需要防止这类漏洞,采用apache rewrite方法的时候用 NC 表示不区分大小写匹配 ,F表示forbidden

RewriteRule ^images/.*\.php – [NC,F]

uc_client/client.php 功能介绍

uc的客户端uc_clinet/client.php 功能

以uc_get_user 为例子

function uc_get_user($username, $isuid=0) {
	$return = call_user_func(UC_API_FUNC, 'user', 'get_user', array('username'=>$username, 'isuid'=>$isuid));
	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
}
此函数调用 client.php 内部 UC_API_FUNC 函数,一般来说UC_API_FUNC 是 定值,你在客户端的后台一般设置是mysql方式的同步
那么  
define('UC_API_FUNC', UC_CONNECT == 'mysql' ? 'uc_api_mysql' : 'uc_api_post');
也就是说 UC_API_FUNC 的值是 uc_api_mysql
下面看 uc_api_myql 函数
function uc_api_mysql($model, $action, $args=array()) {
	global $uc_controls;
	if(empty($uc_controls[$model])) {
		include_once UC_ROOT.'./lib/db.class.php';
		include_once UC_ROOT.'./model/base.php';
		include_once UC_ROOT."./control/$model.php";
		eval("\$uc_controls['$model'] = new {$model}control();");
	}
	if($action{0} != '_') {
		$args = uc_addslashes($args, 1, TRUE);
		$action = 'on'.$action;
		$uc_controls[$model]->input = $args;
		return $uc_controls[$model]->$action($args);
	} else {
		return '';
	}
}
表示的是 包含了 control/$model.php  运行里面的 on_xxx 比如  onget_user 就是一例
function onget_user() {
		$this->init_input();
		$username = $this->input('username');
		if(!$this->input('isuid')) {
			$status = $_ENV['user']->get_user_by_username($username);
		} else {
			$status = $_ENV['user']->get_user_by_uid($username);
		}
		if($status) {
			return array($status['uid'],$status['username'],$status['email']);
		} else {
			return 0;
		}
	}
这里明显是 $_ENV['user'] 是 model/user.php 的user类引入的
在contrl/user.php 里面看的很清楚
	function usercontrol() {
		parent::__construct();
		$this->load('user');
		$this->app = $this->cache['apps'][UC_APPID];
	}
通过base类的load 函数 

	function load($model, $base = NULL) {
		$base = $base ? $base : $this;
		if(empty($_ENV[$model])) {
			require_once UC_ROOT."./model/$model.php";
			eval('$_ENV[$model] = new '.$model.'model($base);');
		}
		return $_ENV[$model];
	}

那么好了,在user->get_user_by_username 和  $user->get_user_by_uid 函数里面选择一个,根据 isuid 来判断参数是否是uid,
从而到uc数据库的UC_DBTABLEPRE."members 根据uid还是username查找.得到的值被重新组织了!!!
return array($status['uid'],$status['username'],$status['email']);

如果想得到 uid ,需要从 [0] 里面的!!!

支付宝手机网页支付

支付宝手机网页支付

参考此文 http://www.tuicool.com/articles/aqeA7r

手机网页支付产品由手机网页即时到账授权接口(alipay.wap.trade.create.direct)、

手机网页即时到账交易接口(alipay.wap.auth.authandexecute)两个接口组成。

必须先调用手机网页即时到账授权接口(alipay.wap.trade.create.direct)获得授权令牌,

再调用手机网页即时到账交易接口(alipay.wap.auth.authandexecute)完成付款。

wordpress无法上传图片

wordpress_ini_get_upload_media

wordpress 出现上传媒体文件 最大值是0的情况,多是php.ini 里面禁用了 ini_get 函数,
解决方式是,手动设置个值,在wp-include/media.php 里面

function wp_max_upload_size() {
        return 1024 * 1024 * 2 ; // phpsir 修改 最大2M
	$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
	$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );

	/**
	 * Filter the maximum upload size allowed in php.ini.
	 *
	 * @since 2.5.0
	 *
	 * @param int $size    Max upload size limit in bytes.
	 * @param int $u_bytes Maximum upload filesize in bytes.
	 * @param int $p_bytes Maximum size of POST data in bytes.
	 */

	return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
}

帝国cms手动分表

1)帝国后台分表管理,建立phome_ecms_news_data_2表
2)insert into  phome_ecms_news_data_2(id)   select id   from  phome_ecms_news_data_1 order by id desc  limit 30001,30000; //每3万条一个分表
3) update phome_ecms_news_data_2 a ,phome_ecms_news_data_1 b set a.classid=b.classid, a.keyid=b.keyid,a.dokey=b.dokey,a.newstempid=b.newstempid,a.closepl=b.closepl,a.haveaddfen=b.haveaddfen,a.infotags=b.infotags,a.writer=b.writer,a.befrom=b.befrom,a.newstext=b.newstext where a.id=b.id; // 更新 phome_ecms_news_data_2 的其它字段
4) update phome_ecms_news set stb =2 where id in (select id from phome_ecms_news_data_2); // 更新news表的stb字段
5) 要分更多表,依次类推

nginx location 指令匹配顺序

官方 http://nginx.org/en/docs/http/ngx_http_core_module.html#location
中文有人这样理解 http://www.php100.com/html/program/nginx/2013/0905/5535.html
还有这个 http://blog.sina.com.cn/s/blog_97688f8e0100zws5.html

下面这个理解的不错,
这个 http://blog.chinaunix.net/uid-25196855-id-108805.html

下面的那个 3 是 上尖号和波浪号

摘录如下

nginx-location

获取远程ip地区

注意,此方法运行缓慢,切不可在大量访问处使用!或者请使用缓存!

感谢 http://snowcoal.com/article/324.html

function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
  $output = NULL;
  if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
    $ip = $_SERVER["REMOTE_ADDR"];
    if ($deep_detect) {
      if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
      if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
  }
  $purpose  = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
  $support  = array("country", "countrycode", "state", "region", "city", "location", "address");
  $continents = array(
    "AF" => "Africa",
    "AN" => "Antarctica",
    "AS" => "Asia",
    "EU" => "Europe",
    "OC" => "Australia (Oceania)",
    "NA" => "North America",
    "SA" => "South America"
  );
  if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
    $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
    if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
      switch ($purpose) {
        case "location":
          $output = array(
            "city"      => @$ipdat->geoplugin_city,
            "state"     => @$ipdat->geoplugin_regionName,
            "country"    => @$ipdat->geoplugin_countryName,
            "country_code"  => @$ipdat->geoplugin_countryCode,
            "continent"   => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
            "continent_code" => @$ipdat->geoplugin_continentCode
          );
          break;
        case "address":
          $address = array($ipdat->geoplugin_countryName);
          if (@strlen($ipdat->geoplugin_regionName) >= 1)
            $address[] = $ipdat->geoplugin_regionName;
          if (@strlen($ipdat->geoplugin_city) >= 1)
            $address[] = $ipdat->geoplugin_city;
          $output = implode(", ", array_reverse($address));
          break;
        case "city":
          $output = @$ipdat->geoplugin_city;
          break;
        case "state":
          $output = @$ipdat->geoplugin_regionName;
          break;
        case "region":
          $output = @$ipdat->geoplugin_regionName;
          break;
        case "country":
          $output = @$ipdat->geoplugin_countryName;
          break;
        case "countrycode":
          $output = @$ipdat->geoplugin_countryCode;
          break;
      }
    }
  }
  return $output;
}

shopnc o2o 更换短信接口

修改 api\message\include\Client.php

里面的sendsms函数

function sendSMS($mobiles=array(),$content,$sendTime='',$addSerial='',$charset='GBK',$priority=5,$smsId=8888)
	{
		
		$params = array('arg0'=>$this->serialNumber,'arg1'=>$this->sessionKey,'arg2'=>$sendTime,
			'arg4'=>$content,'arg5'=>$addSerial, 'arg6'=>$charset,'arg7'=>$priority,'arg8'=>$smsId
			);
			
		/**
		 * 多个号码发送的xml内容格式是 
		 * 159xxxxxxxx
		 * 159xxxxxxx2
		 * ....
		 * 所以需要下面的单独处理
		 * 
		 */
		 
		foreach($mobiles as $mobile)
		{
			//array_push($params,new soapval("arg3",false,$mobile));
			 //此处
			 
		}
		//$result = $this->soap->call("sendSMS",$params,$this->namespace);
		
		return $result;
		
	}

curl参数备忘

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Charset: UTF-8,*;q=0.5',
'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: zh-CN,zh;q=0.8',
'Connection: keep-alive',
'Content-Type:application/x-www-form-urlencoded; charset=UTF-8',
'Referer: http://somewww.com',
'X-Requested-With: XMLHttpRequest',
));

phpcms 整合ucenter 的资料

首先此文甚好 http://down.chinaz.com/try/201208/2176_2.htm
需要注意的是phpcms 后台配置需要指明数据库的名字。
另外查看我之前的博文来解决在 phpcms 退出后不发出js通知到ucenter的各个系统。
如果需要在phpcms注册时候自动登陆到ucenter的discuz系统,还需要看这个博文

关于ucenter各个应用如何最快捷知道所有的app,看这里 

wdlinux 和主机宝 在 php curl https的情况下出现 segmenet fault,可能原因是sqlite 3造成的

Centos 6.5 系统 的sqlite 3 的情况下可能出现此问题
解决方法比较蹊跷,首先定位为sqlite 3的方法是
gdb /path/to/php
>run curl_test.php
出现一堆错误,其中显示出sqlite

Starting program: /a/apps/php-5.2.17/bin/php curl_test.php
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00007fffeb461e9c in sqlite3_file_control () from /usr/lib64/libsqlite3.so.0
Missing separate debuginfos, use: debuginfo-install zadmin-2.0.1-0.x86_64