2016-01-07

php imap_errors 解決方式

解封權限即可
https://www.google.com/settings/security/lesssecureapps

https://accounts.google.com/DisplayUnlockCaptcha

2014-11-11

MYSQL InnoDB 交易範例

PDF READ:http://download.dbworld.com.tw/mag_article/s030901903.pdf

mysql_query("BEGIN");

$sql="SELECT * FROM test_string2 WHERE id=3 FOR UPDATE ";

$rs= mysql_query($sql,$link);

$row=mysql_fetch_array($rs,MYSQL_ASSOC);

mysql_query("COMMIT");

2014-07-25

PHP中imagecopyresampled參數解說

bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
 
$dst_image:新建的图片
 
$src_image:需要载入的图片
 
$dst_x:设定需要载入的图片在新图中的x坐标
 
$dst_y:设定需要载入的图片在新图中的y坐标
 
$src_x:设定载入图片要载入的区域x坐标
 
$src_y:设定载入图片要载入的区域y坐标
 
$dst_w:设定载入的原图的宽度(在此设置缩放)
 
$dst_h:设定载入的原图的高度(在此设置缩放)
 
$src_w:原图要载入的宽度
 
$src_h:原图要载入的高度

2014-03-28

document.form1.submit(); 不能動作

http://www.neo.com.tw/archives/000312.html 

[Javascript] 請勿用保留字來取 HTML 的標籤名 

剛剛查一個 javascript 的 bug ,原因是 document.form1.submit(); 不能動作。出現的錯誤訊息是「物件不支援此屬性或方法」。 

這種 document.form1.submit(); 的 javascript 是再平常不過的指令,怎麼可能不支援呢? 

後來才發現,是美工把 submit 的按鈕取名叫 submit,也就是在 HTML 裡面有一行是: 

<input type="submit" name="submit" value="submit"> 

這樣 document.form1.submit(); 就無法執行了,因為 document.form1.submit 已經變成那個按鈕的物件了,自然 submit 的 method 也無法動作。 

因為自己不會犯這種用保留字來取 HTML Tag name 的錯誤,不過遇到對程式不熟的美工,還是會遇到這種狀況,只能自求多福了。

2014-03-26

PHP獲取路徑和目錄方法總結

<? php
/**
 * PHP獲取路徑或目錄實現
 * @link http://www.phpddt.com
 */

//魔術變量,獲取當前文件的絕對路徑
echo "__FILE__: ========> " . __FILE__ ;
echo '<br/>' ;

//魔術變量,獲取當前腳本的目錄
echo "__DIR__: ========> " . __DIR__ ;
echo '<br/>' ;

//dirname返迴路徑的目錄部分,dirname(__FILE__)相當於__DIR__
echo "dirname(__FILE__): ========> " . dirname ( __FILE__ );
echo '<br/>' ;

//$_SERVER['PHP_SELF']和$_SERVER['SCRIPT_NAME']的結果一般相同,他們都是獲取當前腳本的文件名
//只有當php以cgi方式運行時有區別,但是現在幾乎找不到以cgi方式運行php了
echo '$_SERVER["PHP_SELF"]: ========> ' . $_SERVER [ 'PHP_SELF' ];
echo '<br/>' ;

echo '$_SERVER["SCRIPT_NAME"]: ========> ' . $_SERVER [ 'SCRIPT_NAME' ];
echo '<br/>' ;

//當前執行腳本的絕對路徑。記住,在CLI方式運行php是獲取不到的
echo '$_SERVER["SCRIPT_FILENAME"]: ========> ' . $_SERVER [ 'SCRIPT_FILENAME' ];
echo '<br/>' ;

//當前運行腳本所在的文檔根目錄。在服務器配置文件中定義。
echo '$_SERVER["DOCUMENT_ROOT"]: ========> ' . $_SERVER [ 'DOCUMENT_ROOT' ];
echo '<br>' ;

//getcwd()返回當前工作目錄
echo "getcwd(): ========> " . getcwd ();
echo '<br>' ;

echo '<br>' ;
echo "PHP點點通(www.phpddt.com)整理" ;
轉載請註明地址: http://www.phpddt.com/php/get-path.html尊重他人勞動成果就是尊重自己!

2014-03-18

PHP TELNET PTT

class Telnet {
 var $sock = NULL;

 function telnet($host,$port) {
  $this->sock = fsockopen($host,$port);
  socket_set_timeout($this->sock,2,0);
 }

 function close() {
  if ($this->sock)  fclose($this->sock);
  $this->sock = NULL;
 }

 function write($buffer) {
  $buffer = str_replace(chr(255),chr(255).chr(255),$buffer);
  fwrite($this->sock,$buffer);
 }

 function getc() {
  return fgetc($this->sock); 
 }

 function read_till($what) {
  $buf = '';
  while (1) {
   $IAC = chr(255);

   $DONT = chr(254);
   $DO = chr(253);

   $WONT = chr(252);
   $WILL = chr(251);

   $theNULL = chr(0);

   $c = $this->getc();

   if ($c === false) return $buf;
   if ($c == $theNULL) {
    continue;
   }

   if ($c == "1") {
    continue;
   }

   if ($c != $IAC) {
    $buf .= $c;

    if ($what == (substr($buf,strlen($buf)-strlen($what)))) {
     return $buf;
    }
    else {
     continue;
    }
   }

   $c = $this->getc();

   if ($c == $IAC) {
   $buf .= $c;
   }
   else if (($c == $DO) || ($c == $DONT)) {
    $opt = $this->getc();
    // echo "we wont ".ord($opt)."\n";
    fwrite($this->sock,$IAC.$WONT.$opt);
   }
   elseif (($c == $WILL) || ($c == $WONT)) {
    $opt = $this->getc();
    //echo "we dont ".ord($opt)."\n";
    fwrite($this->sock,$IAC.$DONT.$opt);
   }
   else {
    //echo "where are we? c=".ord($c)."\n";
   }
  }
 }
}

2014-02-08

PHP發送POST請求的三種方式

class Request{

    public static function post($url, $post_data = '', $timeout = 5){

        $ch = curl_init();

        curl_setopt ($ch, CURLOPT_URL, $url);

        curl_setopt ($ch, CURLOPT_POST, 1);

        if($post_data != ''){

            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        }

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        curl_setopt($ch, CURLOPT_HEADER, false);

        $file_contents = curl_exec($ch);

        curl_close($ch);

        return $file_contents;

    }


    public static function post2($url, $data){

     

        $postdata = http_build_query(

            $data

        );

     

        $opts = array('http' =>

                      array(

                          'method'  => 'POST',

                          'header'  => 'Content-type: application/x-www-form-urlencoded',

                          'content' => $postdata

                      )

        );

     

        $context = stream_context_create($opts);


        $result = file_get_contents($url, false, $context);

        return $result;


    }


    public static function post3($host,$path,$query,$others=''){


        $post="POST $path HTTP/1.1\r\nHost: $host\r\n";

        $post.="Content-type: application/x-www-form-";

        $post.="urlencoded\r\n${others}";

        $post.="User-Agent: Mozilla 4.0\r\nContent-length: ";

        $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";

        $h=fsockopen($host,80);

        fwrite($h,$post);

        for($a=0,$r='';!$a;){

                $b=fread($h,8192);

                $r.=$b;

                $a=(($b=='')?1:0);

            }

        fclose($h);

        return $r;

    }
}

2014-01-28

PHP DCOM 爬文網頁,自動登入

ref:http://www.blueshop.com.tw/board/FUM20041006152627A9N/BRD20130417225944UFH/2.html
<?php
$browser = new COM("InternetExplorer.Application") or die("can not start internet explorer");
$browser->Visible = true;
$browser->Navigate("http://php.a168a.com/andyto202/login.php");
while (($browser->Busy) || ($browser->readystate != 4) ) {
    com_message_pump(1000);
}
     $browser->Document->passForm->username->INNERTEXT = "abcdef";
     $browser->Document->passForm->password->INNERTEXT = "123456";
     com_message_pump(2000);
//隔兩秒才送出才看得到結果
$browser->Document->passForm->Submit->Click;
//在這裡判斷$iecontent;正確進入才存入cookie;
while (($browser->Busy) || ($browser->readystate != 4) ) {
    com_message_pump(2000);
}
$string = "錯誤";
$iecontent = $browser->Document->body->INNERTEXT;
$iecontent  = iconv("big5","UTF-8",$iecontent);
if (strpos($iecontent,"錯誤")) {
//還有很多判斷例如無此帳號....,每個網頁不一樣請自行增加
echo $iecontent;
}
else {
echo "write cookie ok";
$iecookie = $browser->Document->cookie;
echo $iecookie;
}
$browser->Quit();
?>

2014-01-27

PHP CURL不使用文件存取COOKIE

/*-----保存COOKIE-----*/
$url = 'domain'; //url地址
$post = "id=user&pwd=123456"; //POST数据
$ch = curl_init($url); //初始化
curl_setopt($ch,CURLOPT_HEADER,1); //将头文件的信息作为数据流输出
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //返回获取的输出文本流
curl_setopt($ch,CURLOPT_POSTFIELDS,$post); //发送POST数据
$content = curl_exec($ch); //执行curl并赋值给$content
preg_match('/Set-Cookie:(.*);/iU',$content,$str); //正则匹配
$cookie = $str[1]; //获得COOKIE(SESSIONID)
curl_close($ch); //关闭curl

/*-----使用COOKIE-----*/
curl_setopt($ch,CURLOPT_COOKIE,$cookie);