handoyo Posted February 20, 2009 Share Posted February 20, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2009 Share Posted February 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-767061 Share on other sites More sharing options...
handoyo Posted March 30, 2009 Author Share Posted March 30, 2009 Thanks a lot..Then i better use the default one... Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-796570 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 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* Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-796575 Share on other sites More sharing options...
PFMaBiSmAd Posted March 30, 2009 Share Posted March 30, 2009 There is, but minimal or no documentation/support/development - http://pecl.php.net/package/session_mysql That page links to this site - http://websupport.sk/~stanojr/projects/session_mysql/ Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-796591 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 Hrmm yeah I figured there was an extension already. I figured it would have been less maintained than that though. Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-796597 Share on other sites More sharing options...
laffin Posted March 30, 2009 Share Posted March 30, 2009 I myself prefer using the sqlite session handler as with mysql sessions, ya will have to look it up to enable it with php.ini. but if offers best of both worlds, its fast & small Quote Link to comment https://forums.phpfreaks.com/topic/146115-session-using-database/#findComment-796599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.