分类目录归档:PHP

php-7.2编译出错记录

openssl安装文件找不到:

evp.h找不到时

先export PKG-CONFIG-PATH=”/usr/lib64/pkgconfig”

再./configure ……..

 

php7.2是enable-gd,enable-zip

php7.4更改为with-gd with-zip,囧

php迭代示例

<code>

<?php
echo “<pre>”;
$area = array(
array(‘id’=>113,’area’=>’亚运村’,’pid’=>11),
array(‘id’=>115,’area’=>’奥运村’,’pid’=>11),
array(‘id’=>1,’area’=>’北京’,’pid’=>0),
array(‘id’=>2,’area’=>’广西’,’pid’=>0),
array(‘id’=>3,’area’=>’广东’,’pid’=>0),
array(‘id’=>4,’area’=>’福建’,’pid’=>0),
array(‘id’=>11,’area’=>’朝阳区’,’pid’=>1),
array(‘id’=>12,’area’=>’海淀区’,’pid’=>1),
array(‘id’=>21,’area’=>’南宁市’,’pid’=>2),
array(‘id’=>45,’area’=>’福州市’,’pid’=>4),
array(‘id’=>234,’area’=>’武鸣县’,’pid’=>21)
);

function familytree($arr,$id){
static $list = array();
foreach($arr as $v){
if($v[‘id’]==$id){

familytree($arr,$v[‘pid’]);
$list[] = $v;
}
}
return $list;
}
print_r(familytree($area,113));
?>

</code>

include工作原理php

PHP的inlcude,require,include_once,require_oncej
在include包含文件并执行这个文件时,是先退出php模式并在html模式下解析此文件。

这也是为什么html文件中如果要插入php一定要定义好php标签。

the_content方法不显示内容的问题

查了很多,有的人说是the_content方法被重写,有的人通过改写
我发现我的问题是修改模板的时候,选择了的single导致的,如图
点了自定义模板后,主页设置里面选择了一个静态页面导致。

重放攻击,md5(‘test’,’test’,随机数)

单独的随机数不能避免重放攻击,随机数一般会和签名加密技术,后台验证技术混合以提高破解和重放难度。
重放攻击(Replay Attacks)又称重播攻击、回放攻击或新鲜性攻击(Freshness Attacks),是指攻击者发送一个目的主机已接收过的包,来达到欺骗系统的目的,主要用于身份认证过程,破坏认证的正确性。
从重放攻击的定义上我们可以看到,重放攻击提交给服务器的数据是曾经有效的,如何防止这种数据,对特定信息给与一个特定的随机数,并且这个随机数保存在服务器内,在验证了用户信息前,首先会对随机数进行验证,如果发现提交的随机数和服务器保存的不同则,该条信息无效通过这种方法来防止重放攻击。
常用的防御重放攻击,不会直接暴露随机数,一般随机数会用在MD5,HASH(数字签名)上,比如在对有效值进行MD5加密时添加随机数,如用户名为test,密码为test的MD5加密过程可能为MD5(“test”,”test”,随机数),这样在直接传输时不会暴露出随机值,黑客在提交重放攻击时系统发现MD5签名和系统签名计算后不同则,可被认定为重放攻击。
当然矛和盾是一种存在的,有可能该值刚好又一次的分配给了该用户,可能会重放攻击成功,但这个概率在科学计算上可以被视为0,而且随着随机数的位数的提高,概率会不断降低。

驼峰命名

驼峰命名法就是当变量名或函式名是由一个或多个单字连结在一起,而构成的唯一识别字时,第一个单字以小写字母开始;第二个单字的首字母大写或每一个单字的首字母都采用大写字母,例如:myFirstName、myLastName,这样的变量名看上去就像骆驼峰一样此起彼伏,故得名。

thinkphp5的crud基本操作理解

thinkphp的参数绑定:
Db::execute(‘insert into think_data (id, name ,status) values (?, ?, ?)’, [8, ‘thinkphp’, 1]);

thinkphp的占位符绑定:
Db::execute(‘insert into think_data (id, name , status) values (:id, :name, :status)’, [‘id’ => 10, ‘name’ => ‘thinkphp’, ‘status’ => 1]);

$result = Db::query(‘select * from think_data where id=:id’, [‘id’ => 10]);
dump($result);

thinkphp的查询构造器:
Db::table()和Db::name(),一个是完整的表名,一个是表前缀
$list = Db::name(‘data’)->where(‘id’,5)->select();

db助手函数默认会每次重新连接数据库,因此应当尽量避免多次调用。
$db = db(‘data’);
$db->insert([‘id’ => 3, ‘name’ => ‘thinkphp’]);
$list = $db->where(‘id’,20)->select();

链式操作做复杂查询:
$list = Db::name(‘data’)->where(‘status’,1)->field(‘id,name’)->order(‘id’,’desc’)->limit(10)->select();
dump($list);

thinkphp5中的pathinfo解析,nginx说明

nginx用正则拆分uri,官方的说明,很清楚!!!
thinkphp5必备!!!

Syntax: fastcgi_split_path_info regex;
Default: —
Context: location
Defines a regular expression that captures a value for the $fastcgi_path_info variable. The regular expression should have two captures: the first becomes a value of the $fastcgi_script_name variable, the second becomes a value of the $fastcgi_path_info variable. For example, with these settings

location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;

and the “/show.php/article/0001” request, the SCRIPT_FILENAME parameter will be equal to “/path/to/php/show.php”, and the PATH_INFO parameter will be equal to “/article/0001”.