顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2010年12月5日 星期日

使用 php 產生 /etc/shadow 的 hashed password

/etc/shadow 格式
http://www.linux.org.tw/CLDP/HOWTO/admin/Shadow-Password-HOWTO/Shadow-Password-HOWTO-2.html

<?php
// MD5
echo crypt($_GET['password'], '$1$');

2010年4月22日 星期四

Locking a File

http://docstore.mik.ua/orelly/webprog/pcook/ch18_25.htm

$fh = fopen('guestbook.txt','a')         or die($php_errormsg);
flock($fh,LOCK_EX)                       or die($php_errormsg);
fwrite($fh,$_REQUEST['guestbook_entry']) or die($php_errormsg);
fflush($fh)                              or die($php_errormsg);
flock($fh,LOCK_UN)                       or die($php_errormsg);
fclose($fh)                              or die($php_errormsg);


$fh = fopen('guestbook.txt','a')         or die($php_errormsg);
$tries = 3;
while ($tries > 0) {
    $locked = flock($fh,LOCK_EX | LOCK_NB);
    if (! $locked) {
        sleep(5);
        $tries--;
    } else {
        // don't go through the loop again 
        $tries = 0;
    }
}
if ($locked) {
    fwrite($fh,$_REQUEST['guestbook_entry']) or die($php_errormsg);
    fflush($fh)                              or die($php_errormsg);
    flock($fh,LOCK_UN)                       or die($php_errormsg);
    fclose($fh)                              or die($php_errormsg);
} else {
    print "Can't get lock.";
}

2010年4月15日 星期四

PHPUnit

Change to your php5 installation folder
cd c:\php5 

You have to install pear if you don't have it
go-pear.bat 


For convenience, a REG file is available under C:\php5\PEAR_ENV.reg
This file creates ENV variables for the current user.
Double-click this file to add it to the current user registry.

Start to install phpunit
pear install phpunit/PHPUnit 

optional for phpunit
pear install pear/Image_GraphViz

optional for phpunit
pear install --alldeps pear/Log

Check the installation is fine

phpunit --version
PHPUnit 3.4.12 by Sebastian Bergmann.


Modify phpunit.bat, change PHPBIN to your realpath, like this
set PHPBIN="C:\php5\php.exe"


Set envirment variable "PATH"
PATH=....;C:\php5
and we can call phpunit.bat in anywhere

What kind of assertion do we have ?
Check this, PHPUnit\framework\Assert.php

Examples:
http://www.phpunit.de/manual/current/en/test-driven-development.html

2010年3月15日 星期一

Redis - A persistent key-value database with built-in net interface written in ANSI-C for Posix systems


Redis
http://code.google.com/p/redis/

Redis is an advanced key-value store. It is similar to memcached but the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists, sets, and ordered sets

A twitter clone by Redis + PHP
http://code.google.com/p/redis/wiki/TwitterAlikeExample

2010年2月2日 星期二

2010年1月25日 星期一

PRADO PHP Framework

http://www.pradosoft.com/

Qiang Xue - founder of PRADO framework, core development
He is in developer team of Yii Framework now.

PRADOTM is a component-based and event-driven programming framework for developing Web applications in PHP 5. PRADO stands for PHP Rapid Application Development Object-oriented.

Main Features of PRADO

  • Object-oriented and highly reusable code
  • Event-driven programming
  • Separation of presentation and logic
  • Configurable and pluggable modular architecture
  • Full spectrum of database support
  • Feature-rich Web components: HTML input controls, validators, datagrid, wizard...
  • AJAX-enabled Web components
  • Built-in support of internationalization (I18N) and localization (L10N)
  • Customizable and localizable error/exception handling
  • Multiway message logging with filters
  • Generic caching modules and selective output caching
  • Extensible authentication and authorization framework
  • Security measures: cross-site script (XSS) prevention, cookie protection...
  • XHTML compliance
  • Rich documentation and strong userbase

2010年1月22日 星期五

Zend Server Community Edition

http://www.zend.com/en/products/server-ce/index







Yii : How to upload a file using a model

How to upload a file using a model
http://www.yiiframework.com/doc/cookbook/2/


Multi File upload - CFileValidator and CUploadedFile
http://www.yiiframework.com/forum/index.php?/topic/3035-multi-file-upload-cfilevalidator-and-cuploadedfile/

Usefull Yii Extension


Datafilter
This extension can be used to add search and filtration capabilities to data grids.
http://www.yiiframework.com/extension/datafilter/

grbac
This module is for User-Management
http://www.yiiframework.com/extension/grbac/

extendedclientscript
With this extension you can transparently reduce page load times by combining and compressing the used Javascript and CSS files.
http://www.yiiframework.com/extension/extendedclientscript/

euploadify
This extension adds a flash based file-upload with progress-bar and multi-file upload capability.
http://www.yiiframework.com/extension/euploadify/

cfile
This extension offers commonly used functions for filesystem objects (files and directories) manipulation.
http://www.yiiframework.com/extension/cfile/

esanitizer
This extension sanitizes all user input ($_POST, $_GET, $_COOKIE,$_FILES) with html purifier to protect against XSS
http://www.yiiframework.com/extension/esanitizer/

cvsout
http://www.yiiframework.com/extension/csvout/reviews/

printout
http://www.yiiframework.com/extension/printout/

Image Extension, Convert Kohana Image Library to Yii

Provides methods for the dynamic manipulation of images. Various image formats such as JPEG, PNG, and GIF can be resized, cropped, rotated and sharpened.

http://www.yiiframework.com/extension/image/

How to add more information to Yii::app()->user

在 Yii 中,一般情況會用
$id=Yii::app()->user->id; // 取得 username

第一次在 view 裡面使用時,覺得很怪異,我要 id 怎麼取到 username (LoginID)...

以下文件說明
1) 如何把 id 取代成 table 的 id 欄位 (sequence id)
2) 如何增加 user 的欄位,如 lastLoginTime

http://www.yiiframework.com/doc/cookbook/6/

2010年1月21日 星期四

Yii extension:從 mwb file 產生 model

mwbmodelcommand  

http://www.yiiframework.com/extension/mwbmodelcommand/

php.ini 需載入 zip extension,不然會出現以下錯誤

Warning: simplexml_load_file(): I/O warning : failed to load external entity "zip://db.mwb#document.mwb.xml" in ...commands\shell\mwbModelCommand.php on line 78

2010年1月20日 星期三

DooPHP Sitemap Generator tool

可以用來快速產生 route table 及 controller




DooPHP Sitemap Generator tool from Leng Sheng Hong on Vimeo.

2010年1月12日 星期二

Drupal Translation



Drupal 的 Translation 是類似 GNU Gettext 的做法
直接用特定函式把要 transalation 的字串包起來,然後用工具 (potx-cli.php) 把這些字串從 code  extract 成文字檔,再用一般的 text editor 去修改成 target language。

Translation template extractor (含 potx-cli.php)
http://drupal.org/project/potx
Command line extraction: Copy potx.inc and potx-cli.php to the directory you would like to generate translation templates for and run php potx-cli.php. The translation templates will get generated as separate files in the current directory. Use php potx-cli.php --help to get a list of command line options.