
17-09-2006, 14:16
|
 |
|
|
חבר מתאריך: 02.10.05
הודעות: 2,355
|
|
יש לי דרך יעילה לעשות את זה.. הנה הדף LOGIN האוניברסלי שלי 
קוד PHP:
<?php //-------------------------------------------------------------------------------------------- //this script is part of movieSYS project! //a movie arrengement system //login system //the name of the code is logger //programmed by nadav tenenbaum //begin 24.12.05 end 27.12.05 //version 2.1.0.0.1.0 //-------------------------------------------------------------------------------------------- //so... you are want to login... ok lets check thet //-------------------------------------------------------------------------------------------- //set vars //-------------------------------------------------------------------------------------------- $failed=FALSE; $err_msg=NULL; //-------------------------------------------------------------------------------------------- //set encoding //-------------------------------------------------------------------------------------------- header("Content-type: text/html; charset=utf8"); //-------------------------------------------------------------------------------------------- //logout option //-------------------------------------------------------------------------------------------- if(isset($_GET['act'])) { if($_GET['act'] == 'logout') { session_start(); include('db.php'); if(isset($_SESSION['m_log_id'])) { mysql_query("DELETE FROM `sessions` WHERE `id` = '".$_SESSION['m_log_id']."'"); unset($_SESSION['m_log_id']); } if(isset($_COOKIE['client'])) { mysql_query("DELETE FROM `sessions` WHERE `id` = '".$_COOKIE['m_log_id']."'"); setcookie("m_log_id", NULL, time()-60*60*24*367*3); } echo '<center><span>המערכת ניתקה אותך, אתה מועבר עכשיו לדף הראשי</span></center><br /><br />'; echo '<META HTTP-EQUIV="Refresh" CONTENT="2; URL=index.php" />'; exit; } } //-------------------------------------------------------------------------------------------- //check if user send form //-------------------------------------------------------------------------------------------- if($_SERVER['REQUEST_METHOD'] == 'POST') { function my_err($my_msg) { global $failed; global $err_msg; if ($failed == FALSE) { $failed=TRUE; $err_msg .= 'במהלך ההתחברות המערכת נתקלה בבעיות הבאות:'."<br /> \n"; } $err_msg .= "$my_msg <br /> \n"; } //---------------------------------------------------------------------------------------- //welcome to the kernel of the code //---------------------------------------------------------------------------------------- //this script is part of movieSYS project! //a movie arrengement system //error system //the name of the code is warning writer //programmed by nadav tenenbaum //begin 24.12.05 end 25.12.05 //version 1.0.0.0.1.0 //---------------------------------------------------------------------------------------- session_start(); if(empty($_POST['client'])) { my_err("שם המשתמש ריק"); } if(empty($_POST['pass'])) { my_err("הסיסמא ריקה"); } if($_SESSION['sCode'] != $_POST['sCode']) { my_err("קוד האבטחה לא תואם"); } if(isset($_SESSION['m_log_id']) OR isset($_COOKIE['m_log_id'])) { my_err("אתה כבר מחובר למערכת"); } //---------------------------------------------------------------------------------------- //back to login! //---------------------------------------------------------------------------------------- //include database class //---------------------------------------------------------------------------------------- include_once 'db.php'; //---------------------------------------------------------------------------------------- //process vars then they be ready for query //---------------------------------------------------------------------------------------- $_POST['client'] = mysql_escape_string($_POST['client']); $_POST['pass'] = sha1($_POST['pass']); //---------------------------------------------------------------------------------------- //check if there was no failed //---------------------------------------------------------------------------------------- if($failed == FALSE) { //------------------------------------------------------------------------------------ //start sql stuff //------------------------------------------------------------------------------------ $start=mysql_query("SELECT `client`,`pass` FROM `members` WHERE `client`='".$_POST['client']."' && `pass`='".$_POST['pass']."'"); $info=mysql_fetch_array($start); //------------------------------------------------------------------------------------ //is the data is right? //------------------------------------------------------------------------------------ if(($_POST['pass'] == $info['pass'] && $_POST['client'] == $info['client'])) { $id = sha1(time()); mysql_query("INSERT INTO `sessions` VALUES ( '".$id."', '".$_POST['client']."', '".$_POST['pass']."' )"); if(empty($_POST['cookie'])) { $_SESSION['m_log_id'] = $id; } else { setcookie("m_log_id", $id, time()+60*60*24*367*3); } //-------------------------------------------------------------------------------- //yes it is! //-------------------------------------------------------------------------------- mysql_close(); header("Location:index.php"); exit; } else { //-------------------------------------------------------------------------------- //you are so cool... //-------------------------------------------------------------------------------- my_err("the client or the password are incorrect"); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="rtl"> <head> <title>נכנסת למקום מוגבל</title> <?php include('menu.php') ?> <form action="login.php" method="POST" enctype="application/x-www-form-urlencoded" name="log"> <center> <?php if($failed == TRUE) { //---------------------------------------------------------------------------- //ha ha.. not cool enough //---------------------------------------------------------------------------- echo '<span>'.$err_msg.'</span>'; } ?> <table> <tr> <td><span>שם משתמש:</span></td> <td><input type="text" name="client" /></td> </tr> <tr> <td><span>סיסמא:</span></td> <td><input type="password" name="pass" /></td> </tr> <tr> <td colspan="2"> <img src="image.php" title="קוד אבטחה" border="1" /><br /> <span>קוד אבטחה:</span> <input type="text" name="sCode" maxlength="6" /> </td> </tr> <tr> <td><input type="submit" value="שלח" name="submit" /></td> <td><span>זכור אותי?</span><input type="checkbox" value="cookie" checked="checked" /></td> </tr> </table>
<center> </form> </body> </html>
והנה תמונת מסך של מה שיוצא:
_____________________________________
|