如何将会话保存到mysql中?

han*_*oyo 2 php mysql

我需要有关将会话保存到mysql的帮助.

现在我正在为我的登录系统使用php普通会话.

这是我的代码:

auth.php

<?php
session_start();
include('db.inc.php');
$email=mysql_real_escape_string($_POST['email']);
$pwd=mysql_real_escape_string($_POST['pwd']);
$sql="Select member_id,email,password,nama,type from users where email='$email' and password=md5('$pwd')";
$exec=mysql_query($sql);
$result=mysql_fetch_array($exec);
if ($result['type'] == "member")
{
$_SESSION['nama']=$result['nama'];
$_SESSION['id']=$result['member_id'];
header('location:member.php');
}
else
{
    echo 'Anda gagal login';
   header('location:index.php');
}
?>
Run Code Online (Sandbox Code Playgroud)

member.php

<?php
session_start();
include('output_fns.php');
if(!$_SESSION['nama'])
{
    header('location:index.php');
}
else
{
do_kepala('Member');
echo 'Welcome &nbsp;&nbsp;&nbsp;' . $_SESSION['nama'];
menu_member();
?>
Run Code Online (Sandbox Code Playgroud)

rye*_*guy 5

您将不得不为会话保存处理程序定义自定义函数.当然,您还必须在MySQL数据库上创建一个表.有许多复杂的步骤,您可以在这里找到所有这些步骤.