用Curl登录Plesk后台备份文件

Posted in PHP on January 11th, 2010 by Adam

Plesk很不厚道,备份文件不能轻易用压缩软件解压,很不方便。之前我也用过outlook的办法解压plesk备份文件,不过这个方法在系统升级后已经失效。

我们可以用PHP的Curl模块备份网站文件。
其主要思想是通过Curl直接抓取https后台下,file manager中的文件。
备份环境:Apache/2.2.11 (Win32) SVN/1.5.6 PHP/5.3.0 DAV/2
主要Curl代码如下

$ch = curl_init();

//https支持
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($ch, CURLOPT_URL, $url); //plesk 后台路径
curl_setopt($ch, CURLOPT_USERPWD, USERNAME.’:’.PASSWORD); //plesk 后台用户名,密码

curl_setopt($ch, CURLOPT_HEADER, 1); //输出header部分
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if ($method == ‘POST’) {
curl_setopt($ch, CURLOPT_POST, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); //post提交的urlencode数据
}
$data = curl_exec($ch);
curl_close($ch);

[巾*(穴/登)]

Posted in Mysql on January 9th, 2010 by Adam

论坛里有些汉字比较生僻,所以发布到论坛就会成为很怪的字符,例如,我们常常可以看见“[巾*(穴/登)]”这个东西,这是‘正’字的发音,实际上是绘画的画字的意思,但古书里用的“证”字,现在已经念不通。

在PHPMyadmin里面搜索:SELECT * FROM `bbs_posts` WHERE message like ‘%[巾*(穴/登)]%’;
可是并没搜索到结果。试着把网页编码改为UTF-8,搜索结果就可以看到。

用HTTP_Request2替换Curl更新Twitter

Posted in PHP on January 8th, 2010 by Adam

由于更换服务器,不再支持Curl模块。所以决定使用Pear的HTTP_Request2包来更新更新Twitter。

原Curl代码:

$ch = curl_init($url);
if($postargs !== false){
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
}
if($this->username !== false && $this->password !== false)
curl_setopt($ch, CURLOPT_USERPWD, $this->username.’:’.$this->password);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = curl_exec($ch);
$this->responseInfo=curl_getinfo($ch);
curl_close($ch);
if(intval($this->responseInfo['http_code'])==200){
if(class_exists(‘SimpleXMLElement’)){
$xml = new SimpleXMLElement($response);
return $xml;
}else{
return $response;
}
}else{
return false;
}

换为Pear::HTTP_Request2:

$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$req->setHeader($this->headers);
if($postargs !== false){
$arr_post=explode(“&”,$postargs);
for($i=0,$imax=count($arr_post);$i<$imax;$i++){
$item_arr=explode("=",$arr_post[$i]);
$req->addPostParameter($item_arr[0], $item_arr[1]);
}
}
$req->setBody(”);
$response = $req->send()->getBody();
if (200 == $req->send()->getStatus()) {
return $response;
}else{
return false;
}

下载解压HTTP_Request2来相同目录,如需测试,还需要下载Net_URL2PHPUnit。运行AllTests.php显示如下:

PHPUnit 3.4.6 by Sebastian Bergmann.

……………………………

Time: 0 seconds, Memory: 5.00Mb

OK (33 tests, 80 assertions)

表示安装HTTP_Request2正确。

Tags:

IE8上window.onresize的问题

Posted in Uncategorized on January 5th, 2010 by Adam

今天发现IE8下window.onresize会作用于< select >上, 或者其他Form元素变形的时候.
本来有个脚本用于替换背景,
window.onresize = resize;
function resize() {
window.location.reload();
}
可是选择select或者其他Form元素变形的时候,resize会被触发。

如果去掉
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/REC-html40/transitional.dtd" >
发现没有这个问题,window.onresize没有被触发。

考虑用检测window的宽度是否发生变化,来替代window.onresize。

Tags: ,
RSS Feed