1 require和include函数
几乎相同
唯一区别:require()函数会给出一个致命错误,而include()只给一个警告。
变种require_once和include_once?
防止错误的引入同样的函数库两次。出现重复定义的错误。而原版本的运行速度较快。
2 require用法
php不会查看require函数中文件的扩展名。使用require()语句载入文件page.html,文件内任何php命令都会被处理。但php代码放到php标记之间才会被处理成php代码。否则,代码将被视为文本或html脚本不会被执行
通常,php只解析扩展名被定义为.php的文件。而require函数则不同。
3 调用未定义的函数
检查:
函数名称的拼写是否正确
函数是否存在于所用的php版本库中
4 函数名称的大小写
函数调用不区分大小写
变量名称区分大小写
5 封闭php标记
<?php function my_fun() {?>//这里必须有php封闭标记my function was called.<?php }?>
6 内置函数
内置函数在所有的php脚本中都可以使用但如果声明自己的函数,它们只能在自己的脚本中使用。
php不支持函数重载,不能和内置函数重名。
避免再多个脚本中定义相同的函数名。
7 可变函数
name()并不是一个函数合法名称,但是一个它也可以正确执行,这是根据 name的值来确定。php取出保存在$name中的值,寻找具有那个名称的函数,并且调用该函数。这种函数被称为可变函数。
8 echo对变量的影响
function fn() { $var = "contents";}fn();echo $var; // 什么也没有输出// 如下所示的例子刚好相反。在函数外部声明一个变量,然后在函数内部使用它<?phpfunction fn() { echo "inside the function, \$var = ".$var. "<br/>"; // 创建一个局部变量 $var $var = "contents 2"; // 改变局部变量 $var 的值 echo "inside the function, \$var = ".$var. "<br/>";}$var = "contents 1";fn();echo "outside the function, \$var = ".$var. "<br/>"// outputinside the function, $var = inside the function, $var = contents 2 outside the function, $var = contents 1 // 全局 $var 没有改变
9 global关键字
global可以用来手动指定一个在函数中定义或使用的变量具有全局作用域。
function fn() { global $var; $var = "contents"; echo "inside the function, \$var = ". $var ."<br/>";}fn(); echo "outside the function, \$var = ". $var ."<br/>";// outputinside the function, $var = contentsoutside the function, $var = contents
变量的作用域是从执行global $var这一句开始的。
当一个变量要在整个脚本中都要用到,在脚本的开始处使用关键字global
10 参数引用传递
function increment(&$value, $amount =1) {$value=$value+$amount;}$value = 1;echo $value; // print 1increment($value);echo $value; // print 2

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
