php
主要从安全Security,性能Performance,代码整洁度Code cleanliness角度考虑

- register_globals = Off         [Security, Performance]
- register_long_arrays = Off     [Performance]
- display_errors = Off           [Security]
- log_errors = On                [Security]
- output_buffering = 4096        [Performance]
- register_argc_argv = Off       [Performance]
- magic_quotes_gpc = Off         [Performance]
- variables_order = "GPCS"       [Performance]
- error_reporting = E_ALL        [Code Cleanliness, Security(?)]
- allow_call_time_pass_reference = Off     [Code cleanliness]


安全模式必须要开启
safe_mode = on
safe_mode_gid = off

启动safe_mode,会对许多PHP函数进行限制,特别是和系统相关的文件打开、命令执行等函数

safe_mode_include_dir = [WEBSITE]

运行文件目录
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_

open_basedir = [WEBSITE]

必须要禁用的函数

disable_functions=exec,passthru,popen,proc_open,shell_exec,system,phpinfo, assert

建议禁用的函数disable_functions=chdir,chroot,dir,getcwd,opendir,readdir,scandir,fopen,unlink,delete,copy,mkdir,rmdir,rename,
file,file_get_contents,fputs,fwrite,chgrp,chmod,chown

expose_php = Off

关闭错误信息提示
display_errors = Off

关闭全局变量
register_globals = Off

不允许调用dl
enable_dl = Off

关闭远程文件

allow_url_fopen = Off
allow_url_include = Off

http only 开启
session.cookie_httponly = 1

https secure 开启
session.cookie_secure = 1

明确定义upload_tmp_dir设置为系统tmp目录
ICE for PHP 安装和使用指南
Posted in PHP on 2010/04/29 / 评论(0) »
介绍
ICE 的官网是http://www.zeroc.com。ICE(Internet Communications Engine 网络通讯引擎),是由Corba原核心成员开发的一个开源中间件,据称其各种性能完全优于Corba。


1、下载地址
http://www.zeroc.com/download/Ice/3.2/Ice-3.2.0.tar.gz
http://www.zeroc.com/download/Ice/3.2/IcePHP-3.2.0.tar.gz

2、安装
2.1 安装Ice for C++ 3.2.0
    $tar xzvf Ice-3.2.0.tar.gz
    $cd Ice-3.2.0
    编辑文件config/Make.rules,修改一些参数(可以不修改,按默认值安装)
    $make && make install
    一般这一步不会出问题的,但是编译时间较长,
    如果出问题,一般是缺少一些库,参照出错信息安装相应的库。
   默认安装地址在 /opt/Ice-3.2.0

2.2 安装IcePHP
    $tar xzvf IcePHP-3.2.0.tar.gz
    $cd IcePHP-3.2.0
    $vi config/Make.rules  
       修改 PHP_HOME                ?= /usr/local/php  #php的安装目录,如果已经编译安装过了PHP的话。
    $export ICE_HOME=/opt/Ice-3.2.0 #这一步很重要,否则后面编译会出错,报没有找到IceUtil::stringToInt64()方法
    $make && make install
    
   编译过程我还遇到如下错误
  

Marshal.cpp:1932: error: 'ZVAL_ADDREF' was not declared in this scope
  

   通过Google,ICE的论坛有技术支持,解决办法是在 Marshal.cpp将ZVAL_ADDREF 改成 Z_ADDREF_P。这种错误我不知道笔误还是故意,希望在以后的版本会修复这个bug。

   安装完成后,会在/opt/下出现IcePHP-3.2.0目录,lib/IcePHP.so就是下面要用到的。

2.3 配置php.ini
   vi /etc/php.ini

在任意位置增加两行:
extension_dir = /opt/IcePHP-3.2.0/lib/
extension=IcePHP.so
ice.profiles = /etc/ice.prop

#也可以将IcePHP.so拷贝到原来的php的extension_dir目录

2.4.准备/etc/ice.prop
vi /etc/ice.prop

加入以下两行:

[profile_demo]
ice.slice=/usr/local/apache2/htdocs/hello/Hello.ice

这两行的意思就是,增加一个ice的配置,名字是profile_demo,slice文件是…Hello.ice



3.创建一个php client
方法一:
将ice文件编译成php文件
举例,
$ /opt/Ice-3.2.0/bin/slice2php Printer.ice #生成一个Printer.php文件

编写一个client.php例子

<?php?
ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . '/opt/Ice-3.2.0/php');
//Ice.php是
require 'Ice.php';?
require 'Printer.php';?
?
$ic = null;?
try?
{?
$ic = Ice_initialize();?
$base = $ic->stringToProxy("SimplePrinter:default -p 10000");?
$printer = Demo_PrinterPrxHelper::checkedCast($base);?
if(!$printer)?
throw new RuntimeException("Invalid proxy");?
?
$printer->printString("Hello World!");?
}?
catch(Exception $ex)?
{?
echo $ex;?
}?
?
if($ic)?
{?
// Clean up?
try?
{?
$ic->destroy();?
}?
catch(Exception $ex)?
{?
echo $ex;?
}?
}?
?>





4、ICE在PHP应用中的缺点,无法使用PHP编写Server端,其实这也是PHP的一个缺陷——没有完善的多进程和多线程管理机制。因此,Server端可以采用ICE所支持的其它语言进行编写,比如JAVA/C++/VB/PYTHON等。




参考:

“先进的互联互通技术”–使用ice联通php和java

ICE-高效的中间件平台
ICE的PHP扩展(翻译) 之一 概述和简介


zend 公司目前还没有开发兼容 window 7 64 位的 zend studio 5.5版本的软件,我从zend 论坛里头搜到一个帖子,有高人已经能搞定了Zend Studio 5.5 on Windows 7,我自己试用了好久,最终也算搞定了。为了节约时间,我将中文的理解记下:

1. 下载并安装最新的 JRE for Windows: http://java.com/en/download/manual.jsp
2. 下载并安装 WinRAR: http://rarlabs.com (be sure to install with Explorer shell extension).
3. 下载 Zend Studio 5.5.1
4. 点右键将ZendStudio-5_5_1.exe 解压缩在当前目录.
5. 进入解压后产生的目录 Windows\resource (主要这不是系统盘的windows/resources).
6. 然后将 "jre" 目录重命名为 "jre backup".
7. 然后复制 C:\Program Files (x86)\Java\jre6 目录到Windows/resource/下 重命名 "jre6" 为 "jre".
8. 回到上级Windows/目录下执行ZendStudio-5_5_1.exe ,安装.
9. 安装完成后,从windows/resource目录下将"jre backup" 目录复制到 Zend Studio 5.5 的安装目录下.
10. 将已安装目录下的 "jre" 重命名为 "jre another backup"
11. 然后将"jre backup" 重命名为 "jre"
12. 最后一步很关键,要设置ZDE.exe的运行兼容性,右键选择ZDE.exe的属性-->兼容性-->以兼容模式运行这个程序,选择 Windows Vista。

胜利!由于我一开始不知道兼容性怎么设置,总是碰到渲染的色彩问题,软件界面显示不正常,浪费了3个多小时的时间。

希望对后人有所帮助。我喜欢Zend Studio 5.5,讨厌后面集成到Eclips。
PHP SSO 开源软件--Xppass
Posted in PHP on 2009/10/30 / 评论(2) »
最近做了一个新的开源项目,PHP 单点登录系统 Xppass,访问地址在http://xppass.googlecode.com

项目特点:

1、提供三种解决方案Cookie方案、Session方案和Ticket方案,根据需求任选其一。

2、可采用哈希分表设计,支持亿万级别用户数据量存储。

3、提供用户名和电子邮箱两种互补注册方式。

4、实现安全登录技术,采用密码MD5加密传输和hmac身份验证。

5、提供自动安装程序。

6、支持多语言版本。

点击在新窗口中浏览此图片

官方网址:http://xppass.googlecode.com


最近花了很多时间和心思开发的一个开源项目,KFL,--Kindly, Fast, Light的简称。
项目在GoogleCode上托管了。可以访问 http://kfl.googlecode.com

Demo 访问  http://www.kakapo.cn/GoogleCodeKFL/Admin/    用户名 admin 密码 123456

KFL是一个轻快的、友好的、MVC模式的PHP开发框架,基于应用层程序框架来解决Webserver集群带来的系列开发问题。
KFL Admin是一个项目在线管理平台,使用KFL框架开发。可以作为学习使用KFL框架的demo。


主要特点:

    * 统一配置,一键同步。
    * 数据片和网页的分布式缓存。
    * 分布式Memcached服务的监控管理。
    * Session会话集群和在线用户统计。
    * 错误日志管理和应用监控。
    * 项目文件系统在线管理。
    * 集成MySQL备份工具phpMyBackupPro。
    * 集成SQLite管理工具SQLite Manager。

中文网站: http://kfl.googlecode.com
最近感觉以前使用的验证码生成函数太差,优化了一下代码,新的效果如下:
点击在新窗口中浏览此图片

字体文件:


源程序:



<?php
$width = "90";
$height = "30";
$charlen = "4";
$bgcolor = "#eeeeee";
$noise = true;
$noisenum = 20;
$border = false;
$bordercolor = "#cccccc";
$font = dirname(__FILE__). "/plugins/ENGR.TTF";
generate($width,$height,$charlen,$font,$bgcolor,$noise,$noisenum,$borer,$bordercolor);

function generate($width,$height,$len,$font,$bgcolor,$noise,$noisenum,$borer,$bordercolor){
    //创建画布
    $image = imagecreatetruecolor ( $width, $height );
    $back = getcolor ($image, $bgcolor );
    imageFilledRectangle ( $image, 0, 0, $width, $height, $back );
    $size = ($width-6) / $len;
    $size = ($size > $height)?$height:$size;

    //为画布添加杂点
    if ($noise == true){
      for($i = 0; $i < $noisenum; $i++) {
        $randColor = imageColorAllocate ( $image, rand ( 150, 255 ), rand ( 150, 255 ), rand ( 150, 255 ) );
        $x1 = rand(0,$width);
        $y1 = rand(0,$height);
        $x2 = $x1+rand(-20,20);
        $y2 = $y1+rand(-20,20);
        imageline ( $image, $x1, $y1,  $x2,  $y2,  $randColor );
      }
    }

    //生成随机数字

    $textall = "0123456789ABCDEFGHHJKLMNPQRSTWXY";
    $code = '';
    $colorArr = array("#006633","#990000","#006699","#663333");
    $angleArr = array(10,-10,-20,20);
    $textColor = getcolor($image,$colorArr[array_rand($colorArr)]);

    //echo $textColor;
    for($i = 0; $i < $len; $i ++) {
      $tmptext = rand ( 0, 31 );
      $randtext = $textall [$tmptext];
      imagettftext ( $image,18, $angleArr[array_rand($angleArr)], 6+$size*$i, 24, $textColor, $font, $randtext );
      $code .= $randtext;
    }
    $_SESSION ['validatecode'] = $code;

    //加上边框
    if ($border == true){
      $bordercolor = getcolor ( $image, $bordercolor );
      imageRectangle ( $image, 0, 0, $width - 1, $height - 1, $bordercolor );
    }


    //生成
    header ( "Content-type: image/png" );
    imagePng ( $image );
    imagedestroy ( $image );
    die;
  }
  function getcolor(&$image,$color) {
    $color = eregi_replace ( "^#", "", $color );
    $r = $color [0] . $color [1];
    $r = hexdec ( $r );
    $b = $color [2] . $color [3];
    $b = hexdec ( $b );
    $g = $color [4] . $color [5];
    $g = hexdec ( $g );
    $color = imagecolorallocate ( $image, $r, $b, $g );
    return $color;
  }

?>

点击在新窗口中浏览此图片
分页: 1/7 第一页 1 2 3 4 5 6 7 下页 最后页 [ 显示模式: 摘要 | 列表 ]