The first is the login page
<form action="" method="post"> <input type="text" name="uname"><br /> <input type="password" name="psw"><br /> <input type="submit" name="btn" value="登录"> </form> <? PHP IF ( isset ( $ _POST [ 'BTN' ])) { $ the uname = $ _POST [ 'the uname' ]; $ PSW = $ _POST [ 'PSW' ]; IF ( $ the uname == "Tom" && $ PSW == 123 ) { echo "login is successful, after 2 seconds goto ............" ; the setcookie ( 'the uname', $ the uname ); header ( "Refresh: 2; the index.php URL =" ); } The else { echo "<Script> Alert ( 'username password is wrong!') </ Script>" ; } } ?>
Then the main page
? < PHP IF (! Isset ( $ _COOKIE [ 'the uname' ])) { echo "<Script> Alert ( 'the current user is not logged!'); The window.location = 'the login.php' </ Script>" ; Exit ; } echo sizeof (); echo "You are." $ _COOKIE [ 'uname'] "Welcome!." ; ?> <a href="quit.php">退出</a>
Exit pages control
<?php setcookie('uname','',time()-10); header("location:login.php");