ייעול קוד | טופס בדיקת התחברות - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

ייעול קוד | טופס בדיקת התחברות


Jonthan ZeiermaN

Recommended Posts

שלום,

אני מנסה לחשוב על ייעול הקוד אימות התחברות שלי, אשמח להצעות ייעול / שיפור / ולביקורת בונה.

 <?php
###################################################################
## Strating Sessions. ##
###################################################################
session_start();
###################################################################
## Set Cases For Functions. ##
###################################################################
switch ($_GET['page'])
{
case 'login':
login();
break;

default:
login();
break;
}
###################################################
$security_code = rand(000000,999999); ##
$_SESSION['security_code'] = $security_code; ##
###################################################################
## Strating Login Function. ##
###################################################################
function Login()
{
################################################################################################
## Require A DB Connection File. ##
################################################################################################
require_once ('db/connect.php'); ##
################################################################################################
if (isset($_POST['login_check']))
{
################################################################################################
## Variables. ##
################################################################################################
$user = mysql_real_escape_string(htmlspecialchars($_POST['user'])); ##
$pass = mysql_real_escape_string(htmlspecialchars(md5($_POST['pass']))); ##
$query = ("SELECT password, groups FROM users WHERE user = '".$user."'"); ##
$result = mysql_query($query) or die("Mysql Getting The Next Error:" . mysql_error()); ##
################################################################################################
if ($row = mysql_fetch_array($result))
{
if($row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 1)
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
$_SESSION['groups'] = $_SESSION['groups'] + 1;
header('Location: index.php?page=Administrators');
}
if($row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 2)
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
$_SESSION['groups'] = $_SESSION['groups'] + 2;
header('Location: index.php?page=Administrators_Deputys');
}
if($row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 3)
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
$_SESSION['groups'] = $_SESSION['groups'] + 3;
header('Location: index.php?page=Workers');
}
mysql_close($db_connection); //Closing The Db Connection.
}
if(htmlspecialchars($_POST['user']) =='' || htmlspecialchars($_POST['pass'])=='' || htmlspecialchars($_POST['security_code_check'])=='')
{
echo 'אנא מלא את כל השדות';
}
else
{
echo 'שם משתמש ואו סיסמא שגויים';
}
}
}
?>

תודה, יונתן.

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...