1、获取客户端真实IP
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $onlineip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {//是否通过代理服务器 $onlineip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $onlineip = $_SERVER['REMOTE_ADDR']; }}
2、php的面向对象
2.1 魔术方法
public function __construct($name, $age) { $this->name = $name; $this->age = $age; } //get方法,直接通过$man->$name调用 public function __set($name, $value) { $this->$name = $value; } //set方法,直接通过$man->$name调用 public function __get($name) { return $this->$name; } public function __toString() { return $this->name."/".$this->age;; }
2.2 继承接口及类
class person implements sayperson{class teacher extends person{interface sayperson { public function say();}
3、打印错误信息
ini_set('display_errors', 'On');
会返回php服务端错误。
4、php 表单令牌
通过表单令牌的方式,避免重复体检,如生成表单时产生一个随机号并写在session里:
" />
在处理时判断表单号和session里的值:
location.href='/';"; exit;}