<?php
// Starting the session
session_start(); //这个似乎要放在html之前?
if(isset($_SESSION['user']))
{
// Code for Logged members
// Identifying the user
$user = $_SESSION['user'];
// Information for the user.
}
else
{
// Code to show Guests
}
?>
Code for Logging a User:
<?php
//Username Stored for logging
define("USER", "user");
// Password Stored
define("PASS", "123456");
// Normal user section - Not logged ------
if(isset($_REQUEST['username']) && isset($_REQUEST['password']))
{
// Section for logging process -----------
$user = trim($_REQUEST['username']);
$pass = trim($_REQUEST['password']);
if($user == USER && $pass = PASS)
{
// Successful login ------------------
// Setting Session
$_SESSION['user'] = USER;
// Redirecting to the logged page.
header("Location: index.php");
}
else
{
// Wrong username or Password. Show error here.
}
}
?>
User can be logged successfully with username as "user" and password as 123456.
Comments on PHP的SESSION处理 <comments />
test said ...
test
--Yefu 13:37, 17 July 2009 (EDT)
rrr said ...
rrrr
--Yefu 13:39, 17 July 2009 (EDT)
ertert said ...
erterrrrrrrrrrrrrrr
--Yefu 13:39, 17 July 2009 (EDT)