search

一、变量与表达式
PHP变量以美元符$开头,以名称作为变量之间的区分,变量名长度为如:$_name=”zhoulang”;//合法    $name=”zhoulang”;//合法   $1name=”zhoulang”;不合法
二、打印与输出变量
1、echo语句,如:echo “123″;
2、printf函数:用于格式化输出字符串,主要用于字符串中以%开头的格式字符串替换(以%开头的格式字符串,在%后面跟有各种格式字符,以说明输出数据的类型、形式、长度、小数点位数)。语法:boolean printf(string format[,mixed args])
如:printf(”%15s”, “some text”);   //运行结果:some text
3、sprintf函数:基本跟printf函数相同,但是它可以将转换后的结果保存到一个字符串变量中,而不是直接输出。
如:$formatted=sprintf(”%15s”,”some text”);
4、printf和sprintf所支持的格式转换字符表
%???打印出百分比符号,不转换
B???整数转换成二进制数
C???整数转成对应的ASCII字符
D???整数转换成十进制数
F???倍精确度数字转成浮点数
O???整数转换成八进制数
S???整数转成字符串
x/X???整数转成小写/大写的十六进制数
三、显示数组与对象
1、print_r($array/$var):打印数组,不过也可以打印普通 变量。
print_r($_GET);//打印使用GET方法传递的表单内容
2、var_dump($object/$array/$var):可以打印对象、数组、已经标量变量。
var_dump($DB);//打印$DB数据库连接对象的内容。
3、var_export($object/$array/$var):输出或返回一个变量的字符串表示。此函数返回关于传递给该函数的变量的结构信息,它和print_r()类似,不同的似其返回的表示似合法的php代码,可以通过将函数的第二个参数设置为true,从而返回变量的表示。
$a = array(1,2,array(”a”,”b”,”c”));
echo var_export($a);
echo “
”;
echo var_export($a, true);
四、变量的变量
在php中,可以创建一个变量的引用,即一个变量中包含其他的变量,称为变量中的变量,也称为动态变量。由于在脚本中变量值不是确定的,因此使用变量的变量来创建变量名并不一定遵循变量名命名规约。
$$var_name = “php5″;
$$var_name=”php5 web开发”;
echo $php5;//显示 php5 web开发
$$name=’123′;
$$name=’456′;
echo ${’123′};//显示456
function myfunc() {
echo “函数内容!”;
}
$f=’myfunc’;
$f();//将调用myfunc函数
五、超级全局变量数组
1、php超级全局变量列表
$_GET[]???-获得以GET方法提交的变量数组
$_POST[]???-获得以POST方法提交的变量数组
$_COOKIE[]???-获取和设置当前网站的Cookie标识
$_SESSION[]???-取得当前用户访问的唯一标识,以数组形式体现,如sessionid以及自定义session数据
$_ENV[]???-当前php环境变量数组
$_SERVER[]???-当前php服务器变量数组
$_FILES[]???-上传文件时提交到当前脚本的参数值,以数组形式体现
$_REQUEST[]???-包含当前脚本提交的全部请求,包含了$_GET、$_POST、$_COOKIE、$_SESSION的所有动作
$GLOBALS[]???-该超级变量数组包含正在执行脚本所有超级全局变量的引用内容
2、$_SERVER超级全局变量数组
1、$_SESSION['PHP_SELF'] ? 获取当前正在执行脚本的文件名
2、$_SERVER['SERVER_PROTOCOL'] ? 请求页面时通信协议的名称和版本。例如,“HTTP/1.0”。
3、$_SERVER['REQUEST_TIME'] ? 请求开始时的时间戳。从 PHP 5.1.0 起有效。和time函数效果一样。
4、$_SERVER['argv'] ? 传递给该脚本的参数。我试了下,get方法可以得到$_SERVER['argv'][0];post方法无法给他赋值。
5、$_SERVER['SERVER_NAME'] ? 返回当前主机名。
6、$_SERVER['SERVER_SOFTWARE'] ? 服务器标识的字串,在响应请求时的头信息中给出。 如Microsoft-IIS/6.0
7、$_SERVER['REQUEST_METHOD'] ? 访问页面时的请求方法。例如:“GET”、“HEAD”,“POST”,“PUT”。
8、$_SERVER['QUERY_STRING'] ? 查询(query)的字符串(URL 中第一个问号 ? 之后的内容)。
9、$_SERVER['DOCUMENT_ROOT'] ? 当前运行脚本所在的文档根目录。在服务器配置文件中定义。 如E:\server
10、$_SERVER['HTTP_ACCEPT'] [...]

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

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.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

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.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

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

What is the importance of setting the httponly flag for session cookies?What is the importance of setting the httponly flag for session cookies?May 03, 2025 am 12:10 AM

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.

What problem do PHP sessions solve in web development?What problem do PHP sessions solve in web development?May 03, 2025 am 12:02 AM

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

What data can be stored in a PHP session?What data can be stored in a PHP session?May 02, 2025 am 12:17 AM

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

How do you start a PHP session?How do you start a PHP session?May 02, 2025 am 12:16 AM

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

What is session regeneration, and how does it improve security?What is session regeneration, and how does it improve security?May 02, 2025 am 12:15 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

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.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment