Home  >  Article  >  Backend Development  >  php jquery ajax user login example code_PHP tutorial

php jquery ajax user login example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:48:441138browse

User login means that the user enters the user name and password, clicks on the login page without refreshing, and then uses ajax to submit it to the background program for judgment. If the login is successful, it returns true or relevant user information, thus achieving the user's no-refresh login effect.

php Jquery login without refresh, a very simple one written by myself
Added a judgment that if you are already logged in, the login status will still be displayed after refreshing
Login page file
html page

Send to file
The code is as follows
 代码如下 复制代码









Copy code


 代码如下 复制代码

session_start();
require "conn.php";
$username=$_POST['writer'];
$password=$_POST['pass'];
mysql_select_db($database_lr, $lr);
$sql="SELECT * FROM admin WHERE username='$username' AND password='$password'";
$result = mysql_query($sql);
if( mysql_num_rows($result) >0 )
{
// login sucess
$_SESSION['login_Admin']="Admin";
echo "login ok";

}
else
{
// The user ID found
echo "Login failed, ID error or expired.";
}

?>

The code is as follows Copy code
session_start();<🎜> require "conn.php";<🎜> $username=$_POST['writer'];<🎜> $password=$_POST['pass'];<🎜> mysql_select_db($database_lr, $lr);<🎜> $sql="SELECT * FROM admin WHERE username='$username' AND password='$password'";<🎜> $result = mysql_query($sql);<🎜> if( mysql_num_rows($result) >0 ) { // login sucess $_SESSION['login_Admin']="Admin"; echo "login ok"; } else { // The user ID found echo "Login failed, ID error or expired."; } ?> http://www.bkjia.com/PHPjc/632748.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632748.htmlTechArticleUser login means that the user enters the user name and password, clicks on the login page without refreshing, and then uses ajax to submit to the background program for judgment. If Login successfully returns true or relevant user information, so...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn