Category Archives: PHP

[WordPress] A Method for combining both of plain and custom URLs

In WordPress, we usually set the custom URLs for the purpose of SEO.For the old plain URLs which are previously published to other sites, we should maintain them by redirecting to the new custom URLs. The htaccess setting can simply … Continue reading

Posted in PHP, Web Design, wordpress, 程式設計, 網頁撰寫 | Leave a comment

The Problem of Ternary Operators in PHP

How do you think of the ternary operators in PHP? Recently, I’’ve used the code written as below: echo (1?”Y”:0?”N”:””); The code returns “N” but not “Y”. How does it work? It shoud be like: echo ((1?”Y”:0)?”N”:””); Finally, please follow … Continue reading

Posted in PHP, Programming, 程式設計 | Leave a comment

An easy way to fix SQL injection and XSS

In my current case, I find some PHP codes have flaws in SQL injection and  XSS. After analyzing the codes, I find that the URL pameters are usual in numeric type. So, I just add the codes in the PHP … Continue reading

Posted in PHP, Web Design | Leave a comment

[PHP] Be discreet to use crypt function

Recently, the PHP’s crypt function crashed in my designed new system. In fact, in my database design, the length of password field is 64. It ran fine at CentOS 5.5 with PHP 5.2.x. However, when I moved this system to … Continue reading

Posted in Linux, PHP, Programming, Security, 程式設計, 資訊安全 | Leave a comment

[PHP] MySQL Backup by GMail

[Chinese]        先前已經介紹過有一個好用的MySQL資料庫備份工具(使用PHP):MySQLDump。但是預設的寄信函式,是透過SMTP伺服器寄信,這對於沒有SMTP伺服器的使用者而言,可就傷腦筋了。原先我有找到一篇教學,使用GMail的SMTP伺服器做備份,可惜連結已經失效了。筆者只好自行撰寫,由於程式碼使用GPL授權,基於分享的精神下,便公開給各位。         程式碼下載處:請按我。 [English]I’ve introduced an useful backup tool for backuping MySQL databases (using PHP): MySQLDump. However,the default send mail function uses the SMTP server to send mails, and it may cause some problems … Continue reading

Posted in PHP, Programming, Web Design, 科技, 程式設計, 軟體(Software) | Leave a comment

[PHP] The resources about calling windows programs in PHP

I’ve developed  one library about security and make as a .dll package. Now, I want to use the dll through PHP because my significant webdesign skill is PHP, not ASP.Net. The other reason is that I don’t prefer to install two different … Continue reading

Posted in PHP, Programming, Windows, 程式設計 | Leave a comment

[PHP] Solution for the Message in PHPMyAdmin: Query was empty!

During the few days, I’ve encountered a problem for operating PHPMyadmin at my workstation. It is very strange situation while  clicking the viewing button in PHPMyadmin. Whenever I click the viewing button, the result is always the shown message with … Continue reading

Posted in PHP, 程式設計, 網頁撰寫 | Leave a comment

[PHP] 將_GET與 _POST陣列的變數,轉為全域變數的兩種作法

因為最近要改別人寫的舊專案,該專案的寫法為需要將_GET與_POST陣列的變數,改為全域變數。也就是說,我們可以用$register 直接存取$_GET[‘register’]; 像這類的要求,可以分為兩種解決方法: 1. 如果管理員有給.htaccess操作的權限:那麼,可以在.htaccess加入以下語法: php_value register_globals Onphp_flag register_globals On 2. 如果管理員沒有給.htaccess操作的權限: 我從這篇得到的方法,只要寫一個set_globals.php的程式,程式碼內容如下: 每當有程式要執行時,先加一句 require(‘set_globals.php’); 或include(‘set_globals.php’); 引入該檔案即可。 參考資料[程式][PHP] 如何快速接收POST或是GET的變數,並轉存。

Posted in apache, PHP, 網頁撰寫 | Leave a comment

[PHP] 幸運輪盤點名系統

這學期為了教課,班上人數有60人。一個一個點又太麻煩,想說用抽點的。寫個程式來幫助我產生抽點名單。:)首先,準備MySQL資料庫與一張資料表,以這個範例來說,我有張student的資料表,schema如下: 資料表:student 欄位名稱  資料類型 描述 no VARCHAR(10) 學生學號 name VARCHAR(60) 學生姓名 準備我要的資料庫設定檔: 準備好資料庫連線Class: 準備好點名程式: 上述東西準備好後,就可以開始點名了。:P備註:我好像吃飽太閒! =.=

Posted in PHP, 程式設計 | Leave a comment

[PHP] INI設定與Debug教學

在DoubleService的教學中提及,在開發PHP測試函式庫時,由於各個伺服器對於php.ini的設定可能都不一樣。因此,在測試函式庫之前,最好加入以下幾行,以確保自己的程式正確無虞。 有了上述的程式碼,就可以輕鬆Debug囉。另外,請記得在將程式碼交給客戶之前,把Debug模式關閉喔。至於為什麼要通過這些檢查呢?DobuleService曾經提及: 1. 避免變數名前後不小心打錯。2. 避免不存在的鍵值,隱藏可能的邏輯錯誤。3. 強制變數初始化,避免變數交互引用覆蓋或誤用。4. 強制正規化變數型態,避免隱藏性錯誤。5. 自然養成嚴謹的編程習慣。6. 強化程式本身的環境可攜性。 另外,值得一提的是,並非所有ini設定都可以透過ini_set()這個函式來設定的,只有被系統規範為PHP_INI_ALL或是 PHP_INI_USER的選項,才可以使用ini_set()。若不清楚哪些可設定的話,請參見twphp提供的資料: 參考資料 開發PHP時可能會做的環境設定 PHP開發開啟E_ALL的重要性 List of php.ini directives PHP:ini_set()可更改的項目 Why is the result of E_ALL | E_STRICT the same as only E_ALL? php.ini開啟error設定

Posted in PHP, 程式設計, 網頁撰寫 | Leave a comment