עבר עריכה לאחרונה בתאריך 08.05.16 בשעה 01:52 על-ידי Ice Cold (מנהל הפורום)
אני עובד עפ"י המדריך הבא:
http://www.tutorialspoint.com/php/php_mysql_login.htm
אני עובד עם netbeans , לא מצאתי איך עושים דיבאג ( כמו שעושים בECLIPSE )
מה שקורה כרגע זה שאני מכניס שם משתמש וסיסמא ופשוט לוחץ על התחבר וזה מחזיר אותי לדף לוגין , שום דבר לא קורה.
משהו אני לא עושה נכון .
צרפתי למטה את הקוד הרלוונטי . login.php נראה ככה
<?php session_start() ; include("config.php") ; if ($_SERVER['REQUEST_METHOD']== "POST") { //if (filter_input(INPUT_POST,$_SERVER['REQUEST_METHOD'])=== "POST"){ //if(isset($_POST['password'])){$mypassword = $_POST['password'] ; } //$myusername= \filter_input('INPUT_POST', 'username') ; //$mypassword= \filter_input('INPUT_POST', 'password') ; $myusername = mysqli_real_escape_string($db,$_POST['username']); $mypassword = mysqli_real_escape_string($db,$_POST['password']); //$sql = "SELECT * FROM 'users' WHERE username= '$myusername' and password= '$mypassword'" ; $sql= "SELECT * FROM `users` WHERE `username` = '$myusername' AND `password` = '$mypassword'" ; $result = mysqli_query($db,$sql) ; $row = mysqli_fetch_array($result,MYSQLI_ASSOC); $active = $row['active'] ; $count= mysqli_num_rows($result) ; if($count === 1) { session_register("myusername") ; $_SESSION['login_user'] = $myusername ; //header("location: main2.html") ; header("Location: http://localhost/Mana/main2.php"); exit; } else { //$error = "your login name or password is invalid" ; echo "your login name / password is invalid" ; header("Location: http://localhost/Mana/login.php") ; } }?> <!DOCTYPE html> <html> <head> <title>Login</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="slide.js"></script> <link rel="stylesheet" href="style.css"> <script type="text/javascript"> function validate() { if(document.getElementById("username").value.length === 0 || document.getElementById("username").value.lenght > 9) { alert('אנא הכנס שם משתמש מדויק'); return false; } if(document.getElementById("password").value.length === 0 || document.getElementById("password").value.length >9) { alert('אנא הכנס סיסמא מדויקת') ; return false ; } return true ; } </script> <style> .container{ width:auto; max-width: 680px; padding : 0 15px; } h3{ text-align: center; } </style> </head> <body> <img src="LOGO.jpg" alt="Logo" class="img-responsive center-block"/> <div class="container"> <h3 class="text-center">אנא הכנס את פרטיך</h3> <form id="login" name="login" action="" method="post" onsubmit="return validate()" accept-charset="utf-8"> <div class="form-group"> <input type="text" class="form-control" id="username" placeholder="אנא הכנס שם משתמש"> </div> <div class="form-group"> <input type="password" class="form-control" id="password" placeholder="אנא הכנס סיסמא"> </div> <center> <a href="forgotpwd.html"> שכחתי סיסמא</a> <br> <a href="signup.html"> הרשם</a> </center> <button id="btnlogin" type="submit" class="btn btn-primary center-block"> התחבר</button> </form> </div> </body> </html>
|
ככה נראה ה session.php :
<?php include('config.php'); session_start(); $user_check = $_SESSION['login_user']; $ses_sql = mysqli_query($db,"SELECT `username` FROM `users` WHERE `username` = '$user_check'"); $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC); $login_session = $row[`username`]; if(!isset($_SESSION['login_user'])){ header("location:login.php"); } ?>
|
וככה נראה ה config.php למרות שבוודאות אין איתו בעיות :
<?php define('DB_SERVER', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', ''); define('DB_DATABASE', 'sitedb'); $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); ?>
|
תודה מראש.
מילוי סקרים בתשלום למי שמעונין ,
משלם בזמן וקל להגיע ליעד :
https://goo.gl/EJh6V2