我有一个登录脚本,我正在使用,目前正在工作,但我想添加一些额外的功能,如显示名称,一些首选项等我想将用户ID存储在会话中,以便我们可以在浏览网站进行查找时使用它,但我不知道如何解决此问题。任何帮助非常感谢...代码如下。当他们登录时检索并存储关于用户的其他信息
<?php
include_once $_SERVER['DOCUMENT_ROOT'] .
'/includes/magicquotes.inc.php';
if (isset($_GET['login'])){
include 'login.html.php';
exit();
}
if (isset($_GET['security'])){
ob_start();
$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect home"
session_register("myusername");
session_register("mypassword");
header("location:/admin/");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
exit();
}
if (isset($_GET['logout'])){
session_start();
session_destroy();
header("location:/admin/");
exit();
}
session_start();
if(!session_is_registered(myusername)){
header("location:?login");
}
// Display Home Page
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
include 'home.html.php';
exit();
这一切都在[PHP手册](http://www.php.net/manual/en/function.session-start.php) – dbf 2013-04-30 21:14:06