chiprivers Posted December 26, 2006 Share Posted December 26, 2006 Hello all and merry christmas ;DI know there have been several people asking about login scripts but I have managed to create a working one, but I was wondering if anybody could suggest an alternative structure for checking and processing the various steps? I am currently using the following flow to login but I am sure there is a simpler and more efficient way without duplicating my code![code]<?php// is there a user logged in?if ($_SESSION['logged'] == "out") { // has user just submitted login form? if (isset($_POST['login_password'])) { // login details submitted - process and verify user require 'connect_db.php'; $qry_login = "SELECT * FROM members WHERE password = '".$_POST['login_password']."' AND username = '".$_POST['login_user'] ."'"; $rslt_login = mysql_query($qry_login); $num_login = mysql_num_rows($rslt_login); if ($num_login == 1) { // user verified $member = mysql_fetch_array($rslt_login); $_SESSION['logged'] = "in"; $_SESSION['member'] = $member['individual']; $_SESSION['access'] = $member['access']; // show member details require 'logged_in.php'; } else { require 'login_form.php'; } } else { // show login form require 'login_form.php'; }} else { // user is logged in - are they logging out? if (isset($_POST['logout_member'])) { // user loggin out - clear session variables and show login form $_SESSION['logged'] = "out"; $_SESSION['member'] = ""; $_SESSION['access'] = 0; require 'login_form.php'; } else { // user is logged in - show member details require 'logged_in.php'; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31870-processing-order-of-login-script/ Share on other sites More sharing options...
Orio Posted December 26, 2006 Share Posted December 26, 2006 That's a very good structure- does the work and is pretty efficient...You just need to read a bit about SQL injections, because your script is vulnerable. Another I would add is md5/sha1 encryption of the password, with or without a salt string- to improve security.Orio. Link to comment https://forums.phpfreaks.com/topic/31870-processing-order-of-login-script/#findComment-147903 Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Share Posted December 26, 2006 http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php <<<<SQL Injection is here, chiprivers, your homework ;DTed Link to comment https://forums.phpfreaks.com/topic/31870-processing-order-of-login-script/#findComment-147904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.