PHP中的魔术方法
PHP中有下列称之为魔术方法(magic method)的函数:__construct, __destruct ,
__call, __callStatic,__get, __set, __isset, __unset , __sleep, __wakeup,
__toString, __set_state, __clone and __autoload,本文使用__call为实现一个身份验证的简单实例,代码如下: 代码<?php
interface Accountable
{
const ERR_MSG = "error";
public function isLoggedIn();
public function getAccount($user = '');
}
abstract class Authentication implements Accountable
{
private $account = null;
public function getAccount($user = '')
{
if ($this->account != null) {
return $this->account;
} else {
return ERR_MSG;
}
}
public function isLoggedIn()
{
return ($this->account != null);
}
}
class 
相关文档:
PHP是一个很优秀的工具,它可以简单,也可以复杂。不一样的项目,应该用不一样的PHP。
小项目 – 简单而直接的PHP
一般对于一个功能页面在20以下的网站,我们可以用一个很简单的框架结构来写。在这个规模上,我建议是使用比较直接的面向过程编码方法,原因很简 单,没有必要把class文件弄的N ......
在新安装好的mysql ,apahce,php 的时候,如果在代码中使用了sessions_start() 的时候会出现类似以下的错误:
Warning: session_start() [function.session-start]: Cannot send session cooki 等的错误。
请安装如下的思路去修正:
1.在php.ini 中配置 session.savepath='/tmp'
2.开启session.auto_start=1
3.把更改 ......
今天遇到了一个怪问题,我用$fp=fopen("access_log.txt","ab")打开一个文件后开始往里面写数据,写的内容是 'XXX\nXXX\n';
但是奇怪的是 不管我怎么往里面写 他是不换行,记事本里记录的数据 就是 'xxx\nxxx\n',
很是恼火,去网上搜集资料,有的说改成'\r\n'什么的,结果是写进去后还是 'xxx\r\nxx ......
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 92160 bytes) in :\Inetpub\wwwroot04\test.php on line 8
Fatal error: Out of memory (allocated 259,260,416) (tried to allocate 16 bytes) in C:\Inetpub\wwwroot04\test.php on line 8
//ini_set('memory_limit', '-1');
$inde ......
今天确实是无聊了,写了一个备份人人网的日志,到本地html的类。
主要是cURL登录,正则解析页面。
使用方法,最后那个脚本的最后两行改掉,你知道的。或者重新写一个运行脚本:
<?php
include("renren.php");
$test = new renren("你的人人网账号","你的人人网密码");
$test->do ......