Calendar

2010年三月
« 二    
1234567
891011121314
15161718192021
22232425262728
293031  

Translator

PHP-MVC-UML

http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

是个很好的php mvc实现过程展示,已经说地很翔实了。我比较笨,为了更好的理解他的代码实现,用UML把它的设计思路画了一下。

class 

sequence

PHP防止错误显示

防止错误信息出现在浏览器上,可以在相应的语句前面加上@符号,比如下面的连接数据库的语句,在数据库连接失败时不在浏览器上显示错误信息:
$db=@mysql_connect(…);

Zend Studio debug Tips

How to Set $_GET and $_POST vars in the debugger

  1. Click on the ‘variables’ tab of your debug window. You will notice a lot of global, server, and environment vairables. Among them, you should see the empty $_GET and $_POST arrays.
  2. Right-click on either array and choose ‘assign value.’ To input an array, type it in this format:array(value1 => foo, value2 => bar, name => ‘James Cricket’)

ZendDebugger for Freebad

Requester:

disable your ZendOptimizer and eaccelerator
download ZendDebugger.os place to /usr/local/lib/php/20060613/ 

  ZendDebugger.so for freebsd (2.2 MiB, 37 hits)
You need to be a registered user to download this file.

Install:

edit your php.ini. For me php.ini is in /usr/local/etc/

[Zend]
zend_extension=/usr/local/lib/php/20060613/ZendDebugger.so
zend_debugger.allow_hosts=10.10.2.0/24
zend_debugger.expose_remotely=always
zend_debugger.connector_port=10001

restart your apache

Look in the phpinfo( ) got the result below!

zenddebugger

Click to continue reading

php防止恶意访问小程序

本来写PAYPAL IPN response 时用来防止反复尝试的函数,保护性很差,后来改成原地址审核($hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);if(!preg_match(‘/paypal\.com$/’, $hostname)) {…..),所以个就弃用了。在删之前记录不来,应该有更好的算法,不知道谁有研究。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (!avoid_refresh ('15')) die ("Hacking Attempt!!");
.....
.....
.....
function avoid_refresh ($time){
	session_start();
  if (isset($_SESSION["post_sep"])) {
      if (time() - $_SESSION["post_sep"] < $time)  {
      	$_SESSION["post_sep"] = time();
        return false;
      } else {
          $_SESSION["post_sep"] = time();
          return true;
      }
  } else {
      $_SESSION["post_sep"] = time();
      return true;
  }
}

PHP 数据加密

数据加密在我们生活中的地位已经越来越重要了,尤其是考虑到在网络上发生的大量交易和传输的大量数据。如果对于采用安全措施有兴趣的话,也一定会有兴趣了解PHP提供的一系列安全功能。在本篇文章中,我们将介绍这些功能,提供一些基本的用法,以便你能够为自己的应用软件中增加安全功能。

预备知识

在详细介绍PHP的安全功能之前,我们需要花点时间来向没有接触过这方面内容的读者介绍一些有关密码学的基本知识,如果对密码学的基本概念已经非常熟悉,就可以跳过去这一部分。

密码学可以通俗地被描述为对加/解密的研究和实验,加密是将易懂的资料转换为不易懂资料的过程,解密则是将不易懂的资料转换为原来易懂资料的过程。不易懂的资料被称作密码,易懂的资料被称作明码。

数据的加/解密都需要一定的算法,这些算法可以非常地简单,如著名的凯撒码,但当前的加密算法要相对复杂得多,其中一些利用现有的方法甚至是无法破译的 。

PHP的加密功能只要有一点使用非Windows平台经验的人可能对crypt()也相当熟悉,这一函数完成被称作单向加密的功能,它可以加密一些明码,但不能够将密码转换为原来的明码。尽管从表面上来看这似乎是一个没有什么用处的功能,但它的确被广泛用来保证系统密码的完整性。因为,单向加密的口令一旦落入第三方人的手里,由于不能被还原为明文,因此也没有什么大用处。在验证用户输入的口令时,用户的输入采用的也是单向算法,如果输入与存储的经加密后的口令相匹配,则输入的口信一定是正确的。

crypt()函数

PHP同样提供了使用其crypt()函数完成单向加密功能的可能性。我将在这里简要地介绍该函数:

string crypt (string input_string [, string salt])

其中的input_string参数是需要加密的字符串,第二个可选的salt是一个位字串,它能够影响加密的暗码,进一步地排除被称作预计算攻击的可能性。缺省情况下,PHP使用一个2个字符的DES干扰串,如果你的系统使用的是MD5(我将在以后介绍MD5算法),它会使用一个12个字符的干扰串。顺便说一下,可以通过执行下面的命令发现系统将要使用的干扰串的长度:

print “My system salt size is: ”. CRYPT_SALT_LENGTH;

系统也可能支持其他的加密算法。crypt()支持四 种算法,下面是它支持的算法和相应的salt参数的长度:

算法 Salt长度
CRYPT_STD_DES 2-character (Default)
CRYPT_EXT_DES 9-character
CRYPT_MD5 12-character beginning with $
CRYPT_BLOWFISH 16-character beginning with $

Click to continue reading

Pages: 1 2

PHP FixPath Function[路径整理函数]

FixPath Function: fix the dirty paths. PHP路径整理函数.
Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< ?php
echo "nnn    Dirty paths:n";
$paths[] = 'C://////////Windows//////System';               //  C:/System
$paths[] = 'C:HTMLjavascript..examplescolors.html';    //  C:/HTML/examples/colors.html
$paths[] = '/root/./wwwroot/scripts/../././webpage';        //  /root/wwwroot/webpage
$paths[] = 'wwwroot/webpage/../index.php?querystring';      //  wwwroot/index.php?querystring
$paths[] = 'http://www.php.net/manual/en/../../downloads';  //  http://www.php.net/downloads
$paths[] = 'http://www.php.net/downloads/test/test1/test2//./docs.php';    //  http://www.php.net/docs.php
$paths[] = '../downloads/../docs.php';                      //  ../docs.php
$paths[] = 'localhost//projetos/../_arquivos/../';          //   ""
$paths[] = 'C:/downloads/../../../';                        //  C:/
$paths[] = 'downloads/../../../';                           //  ../../
 
foreach ($paths as $path)
{
    echo "n&quot;" . $path . "&quot;  =  &quot;" . fixpath($path) . "&quot;";
}
?>
Note: “//” one more slashes will roll back the root.

Click to continue reading

FindRelativePath Function[找出路径间相对关系]

PHP FUNCTION:Found the relative between the path.
PHP函数:找出路径间相对关系。

Example:

1
2
3
4
5
6
7
8
9
< ?php
$path_a = 'http://www.php.net/manual/en/install.php';
$path_b = 'http://www.php.net/downloads';
 
echo "\nPath A:  " . $path_a;
echo "\nPath B:  " . $path_b;
echo "\nA to B:  " . findRelativePath($path_a, $path_b); //  ../../downloads/
echo "\nB to A:  " . findRelativePath($path_b, $path_a); //  ../manual/en/install.php
?>

Function:

Click to continue reading

Page 1 of 3123