handoyo
handoyo

Reputation: 81

How can I save sessions into mysql?

I need help regarding saving sessions into mysql.

Right now I am using php normal sessions for my login system.

Here is my code:

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');
}
?>

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();
?>

Upvotes: 2

Views: 1206

Answers (1)

ryeguy
ryeguy

Reputation: 66851

You're going to have to define custom functions for the session save handlers . You also have to, of course, make a table on your MySQL database. There are many intricate steps, all of which you can find here.

Upvotes: 5

Related Questions