The session in php can use the client's cookie by default (to distinguish it from cookies in the ordinary sense, I call it session cookie, and cookies in the ordinary sense are cookies) to save the session id, but in php Can the session only use session cookies?
Of course not, otherwise why bother to create a session? It is better to just use cookies. One of the advantages of sessions is that when the client's cookie is disabled, the session id will be automatically attached to the URL, so that the session id can be used Can remember session variables.
Let me write two files to confirm. First, disable cookies in the browser.
[php]
//The file name is test1.php
session_start();
session_register("url");
$url="test2.php";
echo "goto test2.php";
?>
//The file name is test1.php
session_start();
session_register("url");
$url="test2.php";
echo "goto test2.php";
?> [php]
//The file name is test2.php
session_start();
if (session_is_registered("url")) {
echo "congratulations.";
$url="test1.php";
echo "goto test1.php";
} else
echo "failed.";
?>
//The file name is test2.php
session_start();
if (session_is_registered("url")) {
echo "congratulations.";
$url="test1.php";
echo "goto test1.php";
} else
echo "failed.";
?>
Now enter "http://localhost/test1.php" in the browser, move the mouse over the link and look at the address on the status bar. It is not simply "http://localhost/test2.php", but this In the form: "http://localhost/test2.php?phpsessid=6e3610749f7ded3784bc4a4dd10f879b".
You can also view the source file of html, the source file is in this form:
goto test2.php
So this is entirely due to PHP and has nothing to do with the browser, which means that the session is valid no matter what browser you use, not only for IE as some people think.
However, our hyperlink statement is output by the echo statement. What will happen if the hyperlink is not included in the PHP tag ?>? Let’s write an example to verify it. Make test1.php a little bit Modification:
[html]
session_start();
session_register("url");
$url="test2.php";
echo "goto test2.php";?>
(html form)goto test2.php
session_start();
session_register("url");
$url="test2.php";
echo "goto test2.php";?>
(html form)goto test2.php
Enter "http://localhost/test1.php" in the browser, move the mouse to the two links respectively to see if there is any difference? You can see that the two links are exactly the same, and the session ID will be automatically attached later. .So don’t worry that links that are not included in the php tag will become invalid, php will not be so stupid.
But when using it, please note that you must first use the session_start() function to tell php to start using the session, even if you only have html code in this file, such as:
gogogo
…………
I remember someone said that this advantage can only be exerted under linux/unix, but I use win2000p+apache1.3.17+php4.0.4pl1, php is the apache module mode, but it still works. On the contrary, I switched When I went to Linux for testing, it didn't work. In fact, an option during compilation --enable-trans-sid controls whether this function is useful. When compiling according to PHP default, this function is not turned on. Just Just add it when recompiling. My configuration is apache1.3.17+php4.0.4pl1, and php is in apache module mode. After recompiling on Linux, the test with netscape navigator4.7 can pass (this further proves that it has nothing to do with the browser) ).
Session alone cannot be used across windows. Even if you enable cookies, when you have a legal session id in a window (recorded in the session cookie, not in the URL), and then open a new window to enter the same page, You will have a new session id again without affecting the previous window.
If you want to use the same session ID across windows, you can only specify the session ID after the URL. That is to say, if you copy the URL of the window with the session ID and paste it in a newly opened window, it will still be used. Knowing the principle of session id, it is not difficult to implement a cross-window session. You can combine cookies with sessions. First obtain the current legal session id, then record it in the cookie, and then read the cookie in other windows to obtain it. The current session id.

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

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

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

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

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

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

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

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

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.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.