Use the == comparison operator with caution, because PHP is untyped, but the underlying C implementation engine is typed. In the end, there is type conversion. For example, the result of 0=="abc" is true, which may not be what we want.
Semantically speaking, where there is a clear type, we must use the relevant function to explicitly convert it: intval . . .
Unify the PHP file inclusion path in one place, so that when including files in various places in the project, do not bring the path, just the file name, which facilitates the transfer of files
There are still other problems with PHP applications One is not to use PHP global variables directly in functions or class methods, but to provide a separate proxy for accessing global variables, which can be an object or just a simple function. If you access global variables in a class, modify To use objects that proxy global variables so that there is a clear dependency between the two objects, do not use global variables directly inside the function or variables outside global. A function should only use the data passed in as function parameters. Try not to use global variables and go global everywhere, and be careful about repeated submissions of forms. This can take the form of a token.
Determine whether the system is single entry or multiple entry
Pay attention to the encoding: file storage encoding, page encoding, database encoding, user's operating system encoding (when the user directly enters content on the address, FF, Opera The content will be encoded according to the encoding urlencode of the operating system, and IE6 is as it is)
Do not expose the path of the file
After submitting the request, the user closes the browser or clicks the stop button of the browser or other network reasons After disconnection, whether PHP should continue processing or stop processing, how does PHP know the above situation: connection-handling(ignore_user_abort,register_shutdown_function,connection_status...)
Time zone issue, if the application is distributed
explode applied to a null value will produce an array containing 1 item: array(""), but the latter is not false. That is: null is a false value, but after explode(',',null) it is a true value, so be careful with conditions like if(explode(',',$var))
$var = null ;isset($var) results in false.
Security issues of PHP application
Verify input, do not trust the data from the user (GET, POST, COOKIE). For a PHP application, these data should be filtered uniformly. For example, encoding html tags prevents XSS and prevents SQL injection.
At the same time, PHP needs to verify the content that needs to be verified once, because various verifications on the client can be easily skipped (pseudo forms, disabling tools such as js and firebug that can modify html at will).
Be aware of the size of the data submitted by the user. For example, if the post data or get data is too large, buffer overflow may occur
Be careful with non-PHP files on the server. If the application can upload or download files, avoid reading the file directly through the file name and the file name is provided by the user. The user may provide some files that he should not see, but the PHP program reads them. At the same time, do not display the file path in the returned HTML. The file saving path should not be visible to the user. The user may guess other files that they should not see based on these paths
If the session is saved in a file , and there are other unknown users on the web server (such as rented web hosts), you should modify the storage location of the session file, or write the session to the database through the PHP session handler, because the session is saved in the temporary directory by default , others can access it, which is dangerous if information such as passwords are saved in the session.
The above are the relevant solutions to PHP application problems.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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.

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),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
