mysql - PHP, reload the page and display Invalid credentials message? -


i have snippet in index.php file, ask user log on. if details aren't in database system, want reload index.php page , show message "invalid credentials, try again" or that.

how can achieve this? here code:

    <?php session_start();  //check if user logged in if(!isset($_post['id'])) {     $message = 'user logged in already'; }  //check username , password have been submitted if(!isset( $_post['username'], $_post['password'])) {     $message = 'please enter valid username , password'; }  //check username correct length else if (strlen($_post['username']) > 20 || strlen($_post['username']) < 4) {     $message = 'incorrect username length, please try again'; }  //check password correct length else if (strlen($_post['password']) > 20 || strlen($_post['password']) < 4) {     $message = 'incorrect password length, please try again'; }  //check username has alpha numeric characters else if (ctype_alnum($_post['username']) != true) {     $message = "username must alpha numeric"; }  else if (ctype_alnum($_post['password']) != true) {     $message = "password must alpha numeric"; } else {     $admin = "****";     $adminpassword = "****";      //enter valid data database     $username = filter_var($_post['username'], filter_sanitize_string);     $password = filter_var($_post['password'], filter_sanitize_string);      //encrypt password     $password = sha1($password);      //connect database     $sqlusername = "";     $sqlpassword = "";     $sqlhostname = "";      $databasename = "";      try     {         //connection database         $dbhandle = mysql_connect($sqlhostname, $sqlusername, $sqlpassword)            or die("unable connect mysql");         echo "connected mysql<br>";          //select database work         $selected = mysql_select_db($databasename, $dbhandle)                 or die("could not select database");          $selectcustomers = "select *                 customers name =                  '$username' , password = '$password'";          $selectemployees = "select *                 employees name =                  '$username' , password = '$password'";          $selectadmin = "select *                 employees name =                  '$admin' , password = '$adminpassword'";          $customerresult = mysql_query($selectcustomers) or die(mysql_error());         $employeeresult = mysql_query($selectemployees) or die(mysql_error());         $adminresult = mysql_query($selectadmin) or die(mysql_error());          if(mysql_num_rows($customerresult) >= 1)         {             header("location: memberpage.php");             $_session["customer"] = "customer";         }          else if(mysql_num_rows($employeeresult) >= 1)         {            header("location: adminpage.php");            $_session["admin"] = "admin";         }          else if(mysql_num_rows($adminresult) >= 1)         {            header("location: adminpage.php");            $_session["admin"] = "admin";         }          else         {              header("location: index.php");         }          //close connection         mysql_close($dbhandle);     }      catch(exception $e)     {          $message = 'we unable process request. please try again later"';     }   } ?> <html> <head> <title>login</title> </head> <body> </body> </html> 

in last else:

else     {          header("location: index.php");          //i return message here , reload page     } 

try change with:

else     { die(header('refresh: 3; url=index.php').'invalid credentials, wait 3 seconds or click <a href="index.php">here</a> check again.');     } 

where "3" number of seconds wait refresh (reload page).

hope you!


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -