Jump to content

Recommended Posts

Hi all,i want to ask about handling sessions with mysql..Right now i'm using file based session..Suppose i use this code on the auth.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');
}
?>

 

member.php

 

<?php
session_start();
include('output_fns.php');
if(!$_SESSION['nama'])
{
    header('location:index.php');
}
else
{
do_kepala('Member');
echo 'Welcome    ' . $_SESSION['nama'];
menu_member();
$do = $_GET['do'];
//buat milih action
switch ( $do )
{
case "request":
include_once ( "request.php" );
BREAK;

case "isi_testi":
include_once ( "isi_testi.php" );
BREAK;

case "edit_profile":
include_once ( "edit_profile.php" );
BREAK;

default:
include_once ( "member.php" );
BREAK;
}
}
?>

 

What should i do and how do i handle it with mysql..Please point me how to do it..Thanks a lot...

Link to comment
https://forums.phpfreaks.com/topic/146115-session-using-database/
Share on other sites

Why do you think you want to use a database for the session save handler?

 

About the only valid reason for doing so is if you have load balanced web servers and you need session data to be available between all the web servers for one site.

 

After the session save handler has been changed, your code remains the same. If you are having a problem with your code, switching to a database for the save handler won't help with any problem you are having.

 

P.S. A custom session save handler using slow parsed/tokenized/interpreted php code is about 100 times slower than using the built in file save handler that uses complied C code.

  • 1 month later...

Hrmmm....

 

Kind of offtopic...

 

Wonder how hard it would be to write a database session handler in C and have the ability to change a php.ini setting for PHP to use that one.  I'm sure it would still be slower than file based, but it wouldn't have to be parsed on each page load.

 

 

Or memcached....  Hrmmm...

 

*End offtopic*

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.