没有饼干,我有点迷失了。我想创建一个通过 url 传递 SID 的会话,但我不知道如何从另一个页面传递和获取数据。我用谷歌搜索了很多,但 90% 的示例都与 cookie 相关。
这就是我所拥有的。
索引.php
<?php
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",0);
ini_set("session.use_trans_sid",1);
session_start();
?>
<html>
<head>
<title>Index</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="STYLESHEET" type="text/css" href="style.css">
</head>
<body>
<a href="index.php?" class="navactive">Index</a>
<a href="second.php?">Second</a>
<form action="access.php" method="POST">
User: <input type="text" name="user" size="15"/><br>
Pass: <input type="password" name="pass" size="15"/><br>
<button type="submit"/>Ok</button>
<button type="reset"/>Reset</button>
</form>
Logged as: <?php print $_SESSION["name"]; ?>
</body>
</html>
access.php 最后一部分
........
.......
....
if($count==1){
// Register $myusername and redirect to file "second.php"
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",0);
ini_set("session.use_trans_sid",1);
session_name('test');
session_start();
$_SESSION['name'] = $myusername;
header("location:second.php?".SID);
exit;
}
else {
echo "Wrong Username";
}
ob_end_flush();
?>
第二个.php
<?php
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",0);
ini_set("session.use_trans_sid",1);
session_start();
?>
<html>
<head>
<title>Second</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="STYLESHEET" type="text/css" href="style.css">
</head>
<body>
<a href="index.php?">Index</a>
<a href="second.php?" class="navactive">Second</a><br>
<a href="logout.php">Logout</a><br>
Logged as: <?php print $_SESSION["name"]; ?>
</body>
</html>
注销.php
<?php
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",0);
ini_set("session.use_trans_sid",1);
session_start();
session_unset();
session_destroy();
header('Location: index.php');
exit;
?>
- 我必须在“登录为:”中输入什么?"打印 $_SESSION["name"];" 什么都不显示。
-当我登录时,我被重定向到 second.php,然后我单击任何链接,实际记录的会话终止并且 SID 更改。
谢谢!