[转]PHP 5.3中的命名空间使用方法浅述(1 位领导批示)

PHP 5.3 的一个新的重要特性就是 命名空间(namespace)。
这一特性在 PHP5.0x 时候就提出过,后来被取消并安排在 PHP6 中实现。而此次又再次“提前”到了 PHP 5.3 发布,可见开发人员对其的重视以及谨慎的态度。

官方发布时说明文档的内容可能已过期(documentation maybe out dated),所以在这里简单的说明命名空间的用法:首先是声明一个命名空间,加入了新的关键字 namespace ,其应在类文件的开头

全文阅读 »

[备忘]Portable PHP password hashing framework(0 位领导批示)

WordPress 采用的密码加密算法..记录备忘

主要有两个方法:
1.HashPassword 加密密码
2.CheckPassword 进行密码验证

全文阅读 »

Tags : , ,

Discuz的passport与Perl版本的passpost[通用](1 位领导批示)

最近做的一个项目中 需要perl与php进行数据通信.我用LWP::UserAgent的POST方法实现了与PHP程序的连接.
不过在安全上有很大问题.找了找.DZ的passport就直接拿来用了..哇卡卡..

首先是Discuz的passport方法

全文阅读 »

PHP debug三个常用方法(备忘)(0 位领导批示)

一.ReflectionFunction

能打印出一个函数信息

使用方法:

1
2
3
4
function silver() {
    echo 'silver';
}
Reflection::export(new ReflectionFunction('silver'));

 

二.get_defined_functions

这个函数返回一个数组..数组中包含所有已经定义的函数(包括PHP内部函数,所以要慎用).

全文阅读 »

setcookie函数的作用域问题(0 位领导批示)

在不同目录下的文件.不能访问各自设置的cookie

查了一下手册.setcookie函数有一个path参数.可以设置本地cookie的作用域

解释如下:

The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain . If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

另一个参数domain
则是设置网络上cookie的作用域.

解释如下:

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you’d set it to ‘.example.com’. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.

示例:

  1. $setcookday = 30;//设置cookie有效期
  2. setcookie('uname', '银子', time() + ($setcookday * 24 * 60 * 60),'/','qqdang.net'); //分别为cookie名称.cookie值.cookie有效时间.cookie本地作用域.cookie网络作用域

PHP导出Excel格式文件(xls)(1 位领导批示)

PHP导出Excel格式文件(xls),比想像中要简单的多,只需给PHP文件加一个文件头,filename 就是导出的xls文件名,当你点击这个文件的URL时,就会提示你下载xls文件了

header("Content-Type: application/vnd.ms-execl");
header("Content-Disposition: attachment; filename=info.xls");
header("Pragma: no-cache");
header("Expires: 0");

以下是全部代码:

  1. <?php
  2. header("Content-Type: application/vnd.ms-execl");
  3. header("Content-Disposition: attachment; filename=info.xls");
  4. header("Pragma: no-cache");
  5. header("Expires: 0");
  6. require_once(dirname(__FILE__)."/../include/config_base.php");
  7. require_once(dirname(__FILE__)."/../dede/config.php");
  8. require_once(dirname(__FILE__)."/../include/pub_datalist.php");
  9. $dsql = new DedeSql(false);
  10.  
  11.  
  12. echo "订阅日期"."\t";
  13. echo "订阅内容"."\t";
  14. echo "姓名"."\t";
  15.  
  16.  
  17. $dsql->SetQuery("Select * from `TableName` order by `id` desc");
  18. $dsql->Execute();
  19. $i = 1;
  20.  
  21. while($row = $dsql->GetArray())
  22. {
  23.  
  24.  
  25.     echo $row['uTime']."\t";
  26.     echo $row['uCont']."\t";
  27.     echo $row['uName']."\t";
  28.    
  29.     $i++;
  30. }
  31. ?>

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志