完成了php的session加cookie验证,记录一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
session_start();
if($_COOKIE['test']!=''){
        $id=$_COOKIE['test'];
        session_id($id);
        $name=$_SESSION['user'];
        echo $name." ";
?>
        <a href="logoff.php">logoff</a><br />
<?php
}else{
?>
        <form action="login.php" method="post">
                <input type="text" name="username" />
                <input type="submit" value="login" />
        </form>
<?php
}
?>

login.php

<?php
session_start();
$name=$_POST['username'];
setcookie('test', session_id(), time()+3600);
session_register('user');
$_SESSION['user']=$name;
?>
login ok! <a href="index.php">back</a>

logoff.php

session_start();
$id=$_COOKIE['test'];
session_id($id);
session_destroy();
setcookie('test');
unset($_COOKIE['test']);
?>
logoff ok! <a href="index.php">back</a>

转载 http://hi.baidu.com/beckbeckham/blog/item/ffc3f42faf26103e1f308996.html

© 版权声明
THE END
喜欢就支持以下吧
点赞0 分享