我有点失去了没有cookie的工作。 我想创建一个通过URL传递SID的会话,但我不知道如何传递并从另一个页面获取数据。 我google了很多,但90%的例子都是用cookies。没有cookie的PHP会话
这是我的。
的index.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();
?>
second.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>
logout.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;
?>
- 我必须在“记录为:”中输入什么? “print $ _SESSION [”name“];”什么都没显示
- 当我登录时,我被重定向到second.php,然后我点击任何链接,实际记录的会话死亡和SID更改。
thx!
Cookie是传递会话令牌的明智方式。你为什么试图避免它们? – Quentin
使用“session.use_trans_sid”会导致谷歌排名低你的网站。如果可能的话,你不应该使用这个。 “$ _SESSION [”name“]”应该是“$ _SESSION ['name']”...单引号 –
@Quentin我知道,但它是一个大学的练习,我不能使用cookies :( – krovs