Archive for April, 2010

php的session_start函数会附加header信息

Session_start会添加下面这些东西,所以你如果要改这些 header请在Session_start之后修改,否则会被session_start overwrite掉!

Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires Thu, 19 Nov 1981 08:52:00 GMT
Pragma no-cache

No Comments

php unset Header..

如果php已经输出了header

在下面只需要header(‘Pragma:’);就可以了。。

注意最后有一个:

php 5.3.0以后提供了header_remove这个函数,比上面的方法好多了!但是美中不足的是只有5.3.0以后才能用拉~~

No Comments

PKCS5填充 PHP DES算法库

  1. class Bdes extends CBase {
  2.  private $key; //密码
  3.  private $iv; //iv
  4.  private $mcrypt;
  5.  private $blockSize;
  6.  <a href="http://blog.fabrichina.net/archives/201#more-201" class="more-link">Read the rest of this entry &raquo;</a>

No Comments

我常用的一种nginx conf文件的写法

user  www www;
worker_processes 10;
error_log  /var/nginxlogs/error.log error;
worker_rlimit_nofile 21200;
events
{
       use epoll;
       worker_connections 21200;
}
http {
      upstream javaServer {
          server 10.10.10.81:7777;
          server 10.10.10.80:7777;
          server 10.10.10.81:7777;
      }
      upstream phpServer {
          server localhost:81;
      }
      upstream cacheServer {
          server localhost:82;
      }
      include  mime.types;
      default_type  application/octet-stream;
      server_tokens off;
      client_max_body_size 20m;
      tcp_nodelay on;
      include dhport.conf;
#      include cache.dhport.conf;
}

No Comments

apache vs php httpd.conf初始设置

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

<Directory />
 options FollowSymLinks
 AllowOverride all
 Order allow,deny
 Allow from all
</Directory>
AddDefaultCharset utf-8

这样定虚机的时候能省事多了~~

No Comments

新版smarty可能导致php __autoload函数失效。。

升级了smarty结果__autoload没了,不明白为什么。。反正回滚了smarty就好了。。。

No Comments

apache Could not reliably determine the server’s fully 解决。。

修改httpd.conf

ServerName localhost:80

这样就ok了啊~~

No Comments

编译php VS oci8-1.4.1 报错解决

先是从pecl下载了oci8-1.4.1.tar.gz

./configure –with-php-config=/usr/local/php/bin/php-config –with-oci8=/usr/lib/oracle/10.2.0.3/client

make && make install

make的时候报错了

修改MakeFile

INCLUDES = -I/usr/local/php/include/php -I/usr/include/oracle/10.2.0.3/client

找到includes这里,加上-I/usr/include/oracle/10.2.0.3/client

再make就过了!

No Comments

写ini文件(配合parse_ini函数的)

这个函数不是我写的,不得不说,他写的太傻了!

  1. function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {
  2.         $content = "";
  3.  <a href="http://blog.fabrichina.net/archives/179#more-179" class="more-link">Read the rest of this entry &raquo;</a>

No Comments

php生成图片验证码

  1. public function valiCodeImage($valicode_name=valicode’)
  2.         {
  3.                 $str = self::_random(5); //随机生成的字符串
  4.                 $width = 60; //验证码图片的宽度
  5.                 $height = 25; //验证码图片的高度
  6.                 @header("Content-Type:image/png");
  7.                 $im=imagecreate($width,$height);
  8.                 //背景色
  9.                 $back=imagecolorallocate($im,0xFF,0xFF,0xFF);
  10.                 //模糊点颜色
  11.                 $pix=imagecolorallocate($im,187,230,245);
  12.                 //字体色
  13.                 $font=imagecolorallocate($im,40,160,230);
  14.                 //绘模糊作用的点
  15.                 mt_srand();
  16.                 for($i=0;$i<1000;$i++)
  17.                 {
  18.                         imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
  19.                 }
  20.                 imagestring($im, 5, 7, 5,$str, $font);
  21.                 imagerectangle($im,0,0,$width-1,$height-1,$font);
  22.                 imagepng($im);
  23.                 imagedestroy($im);
  24.  
  25.                 if( empty($valicode_name) ){
  26.                         $valicode_name = valicode’;
  27.                 }
  28.                 $_SESSION[$valicode_name] = $str;
  29.                 //echo $str;
  30.         }
  31. private function _random($len)  {
  32.                 $srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  33.                 mt_srand();
  34.                 $strs="";
  35.                 for($i=0;$i<$len;$i++){
  36.                         $strs.=$srcstr[mt_rand(0,61)];
  37.                 }
  38.                 return $strs;
  39.         }

No Comments

php内存换算方式。。

  1. function memConvert($size) {
  2.         $unit=array(‘B’,'KB’,'MB’,'GB’,'TB’,'PB’);
  3.         return @round($size/pow(1024,($i=floor(log($size,1024)))),2).’ ‘.$unit[$i];
  4.         }

No Comments

递归返回所有目录

  1. function listFile($dir,$files=array()) {
  2.    $handle = opendir($dir) or return;
  3.    if(substr($dir,-1)==’/') $dir=substr($dir,0,-1);
  4.    while (false !== ($file = readdir($handle))) {
  5.     if((substr($file,0,1)!=’.') &amp;&amp; is_dir($dir.’/’.$file))   $this->listFile($dir.’/’.$file,&amp;$files);
  6.     else {
  7.      if(substr($file,0,1)==’.') continue;
  8.      $files[]=$dir.’/’.$file;
  9.     }
  10.       }
  11.       closedir($handle);
  12.       return $files;
  13.  }

No Comments