-
cookie参数值
查看全部 -
setcookie()的比较重要的属性
查看全部 -
缓存特性比较
查看全部 -
http两大特性:无状态,无连接。
由于http无状态的特性,要实现购物车和用户识别等功能,需要会话控制技术,而会话控制使用cookie和session技术实现。
查看全部 -
strtotime("+7 days")查看全部
-
php自定义session 调用方式
查看全部 -
php logout
$_SESSION=[];
if (init_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(session_name, '', time()-1, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
session_destroy();
header('location:login.php');
查看全部 -
PHP验证码
查看全部 -
mysqli_connect
mysqli_set_charset
mysqli_select_db
mysqli_escape_string
mysqli_query
mysqli_num_rows
mysqli_fetch_assoc
setcookie('auth', $auth, strtotime('+7 days'))
exit('<script>alert("aaa");location.href="login.php";</script>');
查看全部 -
http特点查看全部
-
addfdfewf
查看全部 -
abc
查看全部 -
<?php
/**
*Cookie的设置、读取、更新、删除
*/
class CustomCookie{
static private $_instance = null;
private $expire = 0;
private $path = '';
private $domain = '';
private $secure = false;
private $httponly = false;
/**
*构造函数完成Cookie参数初始化工作
*@param [array] $options Cookie相关选项
*/
private function __constrct(array $options = []){
$this->setOptions($options);
}
/**
*设置相关选项
*@param array $options Cookie相关选项
*/
private function setOptions(array $options = []){
if(isset($options['expire'])){//是否设置cookie过期时间
$this->expire = (int)$options['expire'];
}
if(isset($options['path'])){
$this->path = $options['path'];
}
if(isset($options['domain'])){
$this->domain = $options['domain'];
}
if(isset($options['secure'])){
$this->secure = (bool)$options['secure'];
}
if(isset($options['httponly'])){
$this->httponly = (bool)$options['httponly'];
}
return $this;
}
/**
*单例模式
*@param [array] $options Cookie相关选项
*@return object 对象实例
*/
public static function getInstance(array $options = []){
if(is_null(self::$_instance)){
$class = __CLASS__;
self::$_instance = new $class($options);
}
return self::$_instance;
}
/**
*设置Cookie
*@param string $name Cookie名
*@param mixed $value Cookie值
*@param array $options 其它选项
*
*/
public function set(string $name, $value, array $options = []){
if(is_array($options)&&count($options)>0){
$this->setOptions($options);
}
if(is_array($value) || is_object($value)){
$value = json_encode($value, JSON_FORCE_OBJECT);
}
setCookie($name, $value, $this->expire, $this->domain, $this->secure, $this->httponly);
}
/**
*获取Cookie
*@param String $name Cookie名
*@return mixed 返回一个null或者一个对象
*/
public function get(string $name){
if(isset($_COOKIE[$name])){
return substr($_COOKIE[$name], 0, 1) == '{' ? json_decode($_COOKIE[$name] : $_COOKIE[$name]);
}else{
return null;
}
}
/**
*删除指定Cookie
*
*/
public function delete(string $name){
}
}
//测试
$cookie = CustomCookie::getInstance();
//var_dump($cookie);
$cookie->set('aa', 11);
$cookie->set('bb', 22);
$cookie->set('cc', 33, ['expire'=>time()+3600])
$cookie->set('userInfo', ['username'=>'shulv', 'age'=>22]);
//var_dump($cookie->get('userInfo'));
var_dump($cookie->get('aa'));
查看全部 -
<?php/***Cookie的设置、读取、更新、删除*/class CustomCookie{ static private $_instance = null; private $expire = 0; private $path = ''; private $domain = ''; private $secure = false; private $httponly = false; /** *构造函数完成Cookie参数初始化工作 *@param [array] $options Cookie相关选项 */ private function __constrct(array $options = []){ $this->setOptions($options); } /** *设置相关选项 *@param array $options Cookie相关选项 */ private function setOptions(array $options = []){ if(isset($options['expire'])){//是否设置cookie过期时间 $this->expire = (int)$options['expire']; } if(isset($options['path'])){ $this->path = $options['path']; } if(isset($options['domain'])){ $this->domain = $options['domain']; } if(isset($options['secure'])){ $this->secure = (bool)$options['secure']; } if(isset($options['httponly'])){ $this->httponly = (bool)$options['httponly']; } return $this; } /** *单例模式 *@param [array] $options Cookie相关选项 *@return object 对象实例 */ public static function getInstance(array $options = []){ if(is_null(self::$_instance)){ $class = __CLASS__; self::$_instance = new $class($options); } return self::$_instance; } /** *设置Cookie *@param string $name Cookie名 *@param mixed $value Cookie值 *@param array $options 其它选项 * */ public function set(string $name, $value, array $options = []){ if(is_array($options)&&count($options)>0){ $this->setOptions($options); } if(is_array($value) || is_object($value)){ $value = json_encode($value, JSON_FORCE_OBJECT); } setCookie($name, $value, $this->expire, $this->domain, $this->secure, $this->httponly); } /** *获取Cookie *@param String $name Cookie名 *@return mixed 返回一个null或者一个对象 */ public function get(string $name){ if(isset($_COOKIE[$name])){ return substr($_COOKIE[$name], 0, 1) == '{' ? json_decode($_COOKIE[$name] : $_COOKIE[$name]); }else{ return null; } } /** *删除指定Cookie * */ public function delete(string $name){ }}//测试$cookie = CustomCookie::getInstance();//var_dump($cookie);$cookie->set('aa', 11);$cookie->set('bb', 22);$cookie->set('cc', 33, ['expire'=>time()+3600])$cookie->set('userInfo', ['username'=>'shulv', 'age'=>22]);//var_dump($cookie->get('userInfo'));var_dump($cookie->get('aa'));
查看全部 -
mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
mysqli_escape_string — 别名 mysqli_real_escape_string() (可以预防数据库攻击)
例子 3
预防数据库攻击的正确做法:
<?php function check_input($value) {// 去除斜杠if (get_magic_quotes_gpc()) { $value = stripslashes($value); }// 如果不是数字则加引号if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; } $con = mysql_connect("localhost", "hello", "321"); if (!$con) { die('Could not connect: ' . mysql_error()); }// 进行安全的 SQL$user = check_input($_POST['user']); $pwd = check_input($_POST['pwd']); $sql = "SELECT * FROM users WHERE user=$user AND password=$pwd"; mysql_query($sql); mysql_close($con); ?>
查看全部
举报