作者ybite (水中影)
看板PHP
标题Re: [请益] 不用cookie能做会员管理吗
时间Wed Jul 19 14:53:38 2006
我觉得这个看起来不太安全 = ="
并考虑到register_globals = off的情况,我会这样改写:
※ 引述《eecir (小君你最可爱了)》之铭言:
: 感谢各位的帮忙
: 看了大家的回文与网路上的文章後
: 我终於想到了关闭cookie後要如何使用session
: 我主要是因为想要在同一台电脑上面做到multi user的功能
: 但又要考虑cookie关闭,让我烦恼了好久
: 以下是我想出来的方式,或许还需要改进,若有不正确的地方
: 还要麻烦大家帮我看看 谢谢各位
test1.php
<?php
session_destroy();
?>
<form id="form1" name="form1" method="post" action="test2.php">
<input type="text" name="a1" />帐号
<input type="text" name="a2" />昵称
<input type="submit" name="Submit" value="输入" />
</form>
我的想法:Session ID让test2.php产生就好
test2.php
<?php //文件名为test2.php
$sid = md5(uniqid(mt_rand(),true));
session_id("$sid");
session_start();
// 请爱用$_SESSION存取Session :)
$_SESSION['id'] = $a1;
$_SESSION['name'] = $a2;
echo $_SESSION['id']."帐号<br>";
echo $_SESSION['name']."昵称<br>";
echo "<a href=test3.php?sid=$sid>goto test3.php</a>";
?>
<form id="form1" name="form1" method="post" action="test3.php">
<input type="text" name="a3" />测试3
<input type="submit" name="Submit" value="输入" />
<input name="sid" type="hidden" value="<?=$sid;?>" />
</form>
我的想法:用time作为Session会比较容易遭受攻击,换个方法
test3.php
<?php //文件名为test3.php
// 考虑到register_globals = off
if($_POST['sid']) $sid = $_POST['sid'];
else $sid = $_GET['sid'];
session_id("$sid");
session_start();
$_SESSION['test3']=$_POST['a3'];
echo $_SESSION['id']."帐号<br>";
echo $_SESSION['name'],"昵称<br>";
echo $_SESSION['test3']."test3<br>";
echo "<a href=test1.php>goto test1.php & session 消失</a>";
?>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.170.71.171
※ 编辑: ybite 来自: 218.170.71.171 (07/19 14:57)
※ 编辑: ybite 来自: 218.170.71.171 (07/19 15:02)