所以爱微网现在讲解先php内置函数
有大小写转换相关函数
文本html标签处理函数
大小写有关函数
strtolower()
strtoupper()
ucfirst()
ucword()
HTML标签相关的字符串格式化函数
nl2br()
htmllentities()
htmlspecialchars()
stripslashes()
strip_tags()
number_format()
strrev()
md5()
在php中所有字符串处理函数 ,都不是在原字符串上修改,而是返回一个新格式化后的字符串
//转换成小写
$a='www.jb51.net';
echo strtolower($a);
//结果:www.jb51.net
//转换成大写
$a='www.jb51.net';
echo strtoupper($a);
//结果:WWW.jb51.net
//首字母大写
$a='www.jb51.net';
echo ucfirst($a);
//结果:Www.jb51.net
//每个单词首字母大写
$a='i love you';
echo ucword($a);
//结果:I Love You
/*
提示:大家都知道大小写,认为小写和大写有区别吗,但是为什么要区分大小写呢
在win系统下php大小写不严格 但是在linux系统下就严禁拉 大小写不能乱写
比如
在自动加载类的时候
function _autoload($className){
include strtolower($className).'.class.php';
}
$obj= new MyClass;
这样就加载myclass.class.php
因为文件名常是小写那么必须转换小写
?>
*/
//nl2br把空格转换成实体
因为一般在浏览器里显示的换行都是
例如在表单留言本里必须要转换不然折行不成功 再多的空格都任务是一个空格
$a='
i
love
you
';
echo $a;
echo nl2br($a);
结果1:i love you
结果2:
i
love
you
//表单提交如果你不进行html标签处理那么就会直接显示样式或者js代码直接运行
/*
当你输入
www.jb51.net
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能css冲突
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'');
提交结果是你查看源码 就会发现没有了
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a);
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能css冲突
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'');
提交结果是你查看源码 就会发现没有了
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a);
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入
www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:
www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'
');
提交结果是你查看源码 就会发现
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a);

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)
