Session是否必须依赖Cookie?
www.ouryh.net 银河技术在线ㄕ整理时间:2001-8-7ㄕ作者: 不详 ㄕ来源: 不详 ㄕ阅读:36
PHP中的session可以默认情况下是使用客户端的Cookie(以便和普通意义上的Cookie区别,我称之为session cookie,普通意义上的Cookie为Cookie)来保存session id的,但是PHP中的session是否只能使用session cookie呢?当然不是,否则何必还弄个session出来,不如直接用Cookie算了.Session的一大优点就是当客户端的Cookie被禁用时会自动把session id附在URL中,这样再通过session id就能记住session变量了.
下面我写两个文件来证实一下,首先在浏览器中设置禁用Cookie.
//文件名为test1.php
session_start();
session_register("url");
$url="//m.sbmmt.com/m/faq/test2.php";
echo "goto test2.php
";
?>
//文件名为test2.php
session_start();
if (session_is_registered("url")) {
echo "Congratulations.
";
$url="test1.php";
echo "goto test1.php
";
}
else echo "Failed.
";
?>
现在在浏览器中输入"http://localhost/test1.php",把鼠标移到链接上看看状态栏上的地址,不是简单的"http://localhost/test2.php",而是这种形式:"http://localhost/test2.php?PHPSESSID=6e3610749f7ded3784bc4a4dd10f879b".你还可以查看Html的源文件,源文件是这种形式:
goto test2.php
所以说这完全是PHP的功劳,和浏览器无关,也就是说无论你用什么浏览器session都有效,而不是有的人认为的只对IE有用.
但是,我们的超链接是语句是由echo语句输出的,如果超链接不包含在PHP的标签 ?>之内会怎样呢?还是写个例子来验证一下,把test1.php稍作修改:
session_start();
session_register("url");
$url="//m.sbmmt.com/m/faq/test2.php";
echo "goto test2.php
";
?>
(Html形式)goto test2.php

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

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.

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool





