[Solve]PHP Warning: ftp_put(): PORT command successful

October 3rd, 2013

PHP Warning:  ftp_put(): PORT command successful. in /mnt/drive2/cron_job/ftp.php on line 49

I got this problem. And I check the solution on the website – add the ftp_pasv() after ftp_login()

But I still got this problem.  And I found out the problem in PHP. The problem is the command exceed the length. Please check your path.

PHP, Program , ,

PHP export Excel Currency Style

April 17th, 2013

<html xmlns:o=”urn:schemas-microsoft-com:office:office”
xmlns:x=”urn:schemas-microsoft-com:office:excel”
xmlns=”http://www.w3.org/TR/REC-html40″>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<head>
<meta http-equiv=”Content-type” content=”text/html;charset=utf-8″ />
<style id=”Classeur1_16681_Styles”>
.hkd {
  mso-number-format: “\0022HKD\0022\#\,\#\#0\.00”;
}
.usd {
  mso-number-format: “\0022USD\0022\#\,\#\#0\.00”;
}
.currency{
  mso-number-format: “\0022$\0022\#\,\#\#0\.00”;
}
</script>
</head>
<body>

<div id=”Classeur1_16681″ align=center x:publishsource=”Excel”>
<table>
<tr>
<td class=”usd”>123,456</td>
</tr>
</table>
</div>
</body>
</html>

Other format

  • Plain Text: mso-number-format:\@
  • Format a number to 2 decimal places: mso-number-format:”0\.00″
  • Comma separators with 2 decimal places: mso-number-format:\#\,\#\#0\.00
  • Date \ Time Formating:
  • American date: mso-number-format:mm\/dd\/yy
  • Month name: mso-number-format:d\\-mmm\\-yyyy
  • Date and Time: mso-number-format:d\/m\/yyyy\ h\:mm\ AM\/PM
  • Short Date: mso-number-format:”Short Date” (05/06/2011)
  • Medium Date: mso-number-format:”Medium Date” (10-jan-2011)
  • Short Time: mso-number-format:”Short Time” (8:67)
  • Medium Time: mso-number-format:”Medium Time” (8:67 AM)
  • Long Time: mso-number-format:”Long Time”  (8:67:25:00)
  • Percentage: mso-number-format:Percent (To two decimal places)
  • Scientific Notation: mso-number-format:”0\.E+00″
  • Fractions – up to 3 digits: mso-number-format:”\#\ ???\/???”
  • Currency (£12.76): mso-number-format:”\0022£\0022\#\,\#\#0\.00″
  • 2 decimals, negative numbers in red and signed: mso-number-format:”\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ ” (1.86-1.66)
  • Accounting Format –5,(5): mso-number-format:”\\#\\,\\#\\#0\\.00_\\)\\;\\[Black\\]\\\\(\\#\\,\\#\\#0\\.00\\\\)”

 

CSS, PHP, Program, Style

熟習Paypal運作

June 7th, 2012

自行寫了一個paypal讓自己多點明白運作

paypal.spritez.com

Ref:
Paypal develop
How Express Checkout Works

PHP, Program

當session遇上header location儲存問題

May 30th, 2012

由於看到網上很多錯誤資訊, 所以自己寫下對session的行動, 研究在於function session_set_save_handler 所得出來的結論, 如有問題, 請指教

由session_start();開始, session只會做普通variable的動作

action.php

session_start();
$_SESSION[‘user’] = ‘abc’;
$_SESSION[‘user’] = ‘ddd’;

直到讀到file完結才會真正儲存session file

所以當action.php session有修改的時候, 最後加了

session_start();
$_SESSION[‘user’] = ‘abc’;
$_SESSION[‘user’] = ‘ddd’;
header(‘Location: index.php’);
exit();

就會即時跳到index.php, 這暫時不會儲存action.php的session, 也當沒有做過東西將他放了一個黑洞(無人不知的地方),直到index.php行完, 才會返回action.php儲存action.php的session
所以當index.php讀取$_SESSION[‘user’], 只會拿回沒有被修改的$_SESSION[‘user’]

PHP, Program , ,

MYSQL – Illegal mix of collations

February 22nd, 2012

<?php mysql_query(“SET NAMES ‘utf8′”); ?>

由於php mysql set utf8_general_ci, 但是在table column set左latin1_swedish_ci, 就會產生

#1267 – Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘like’

SELECT * FROM `table` WHERE `field` like ‘%這些%’

改成

SELECT * FROM `table` WHERE `field` like ‘%這些%’ COLLATE utf8_general_ci

Database, MYSQL, PHP, Program , ,

PHP Filter User agent in session – Bot

February 2nd, 2012

由於php session 儲存在 database, 所以當有bot出現的時候, 我看到session 會儲存大量bot session, 所以要檢查user agent 是否bot. 那bot 就不會儲存session (database, file).

function isNotBot(){

$bots = array(
‘msn’ => ‘http://search.msn.com/msnbot.htm’,
‘yahoo’ => ‘http://help.yahoo.com/help/us/ysearch/slurp’,
‘WebAlta’ => ‘http://www.webalta.net/ru/about_webmaster.html’,
‘google’ => ‘http://www.google.com/bot.html’,
‘media_google’ => ‘mediapartners-google’,
‘soso’ => ‘http://help.soso.com/webspider.htm’
);

$agent = strtolower($_SERVER[‘HTTP_USER_AGENT’]);
foreach($bots as $name => $bot)
{
if(stripos($agent,$bot)!==false)
{
//echo $name;
return false;
}
}

//if( strpos( $_SERVER[‘HTTP_USER_AGENT’], “Googlebot” ) !== false )
//return false;
return true;
}

if(isNotBot())
session_start();

PHP, Program , , , ,

php – 防止訪問

July 2nd, 2011

在一些header設定

define(‘ROOT’, TRUE);

在include file設定

<?php if(!defined(‘ROOT‘)) { exit(‘Access Denied‘); }

如果打開了allow_url_include, 這個方法就可以防止訪問, “ROOT” 可以更改你喜歡的變量, 如果有人利用你一些config file,也需要時間猜你的變量

 

PHP, Program ,

PHP – sort different

June 13th, 2011

<?php
$a = array(2,    "a",  "11", 2);
$b = array(2,    "11", "a",  2);
sort($a);
var_dump($a);
sort($b);
var_dump($b);


/*

Output:

array(4) {
  [0]=>
  string(2) "11"
  [1]=>
  string(1) "a"
  [2]=>
  int(2)
  [3]=>
  int(2)
}
array(4) {
  [0]=>
  int(2)
  [1]=>
  int(2)
  [2]=>
  string(2) "11"
  [3]=>
  string(1) "a"
}

 

*/

?>

PHP , ,

過濾用戶提交過來的GLOBALS信息

June 6th, 2011

if (isset($_REQUEST[‘GLOBALS’]) OR isset($_FILES[‘GLOBALS’])) {
exit(‘Request tainting attempted.’);
}

眾所周知,當php.ini裡面的register_globals=on時,各種變量都被注入代碼,例如來自HTML 表單的請求變量。再加上PHP 在使用變量之前是無需進行初始化的。那麼就有可能導致不安全,假如有人惡意發出這麼一個get請求”http://yourdomain /unsafe.php?GLOBALS=”,那麼就會清除$GLOBALS變量的值而導致不安全。所以我們可以這樣子寫

PHP, Program , , , ,

PHP – Sudoku Solver

June 5th, 2011

自制program – 數獨破解器

訓練program 結構

PHP, Program , ,