tags:

views:

159

answers:

1

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();
?>
+5  A: 

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.

ryeguy
No idea why this was downvoted; it sounds reasonable to me.
R. Bemrose
session_set_save_handler() is exactly what you're looking for.
James Socol