mysql - php login system do not stop or send any error messages when users login incorrectly -
when coded php login system (in mysqli), error not checks if username or password wrong, idk abot this. please me out here.
<?php // if logged in if(isset($_session['user_id'])) { header('location: index.php'); }else {} //error_reporting(0); //mysqli login form //database connection $con = mysqli_connect('localhost', 'root', '', 'console'); //actual login form if(isset($_post['login'])) { session_start(); //explainging details $username = $_post['username']; $password = $_post['password']; //fetching data $result = $con->query("select * users username='$username' , password='$password'"); $row = $result->fetch_array(mysqli_both); //logging in $_session['user_id'] = $row['user_id']; header('location: index.php'); }else{ $wrong = 'username or password wrong'; } ?>
also got check.php redirects /notloggedin.php if not logged in, if user logged in display user_id, when user logsin wrong details go check.php not show , not redirect users /notloggedin.php.
do that? there forgot add, or did wrong???
can write example if have ideas?? thanks.
edit:
instead of using mysqli
got idea @christoandrew, made functions. functions tells system gonna check username first, if username exists gonna make $_session()
for username. again using $_session()
find user_id
username gonna password same user_id
. when checked destroy 'sessions'
made , create $_session()
information user_id
, email
, username
, password
, etc..
. got in way!
if(isset($_post['login'])) { session_start(); //explainging details $username = $_post['username']; $password = $_post['password']; //fetching data $result = $con->query("select * users username='$username' , password='$password'"); $row = $result->fetch_array(mysqli_both); // try checking if there rows returned // if rows greater 0 user exists else // user supplied wrong credentials if(mysqli_num_rows($row) > 0){ //logging in $_session['user_id'] = $row['user_id']; header('location: index.php'); }else{ $wrong = 'username or password wrong'; } // else block below not necessary , validation misplaced }
Comments
Post a Comment