PHP user login and verification code examples

WBOY
Release: 2016-07-25 08:58:39
Original
991 people have browsed it
This article introduces a piece of code for user login and verification using PHP. Friends in need can refer to it.

1. Login page Login.html submit form

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb232">
<title>注册用户登录页面_bbs.it-home.org</title>
</head>
<body>
<h1>程序员之家,欢迎大家的光临。</h1>
<div>
 <form  action="login.php" method="post">
  用户名:<input type="text" name="username" >
  密码:<input type="password" name="password" >
  <p>
   <input type="submit" name="login" value="登陆" >
   <input type="submit" name="zhuce" value="注册">
   </p>
 </form>
</div>
</body>
</html>
Copy after login

2. Login program login.php

<?php
/**
* 用户登录验证代码
* edit bbs.it-home.org
*/
 require_once ("conn.php"); //引入数据库操作文件
 
 $username=$_POST["username"];
 $password=$_POST["password"];
  if(!isset($username) || !isset($password))
   {
   echo"没有用户名或者密码";
   exit();
   }
  else{

//验证用户的合法性
//连接数据库
   $sql="select * from 'user_table' where user_name='$username' ";
   $result=mysql_query($sql);
   if(!$result)
  {
   echo"没有此人";
   exit();
  }
  else
  { 
   $row=mysql_fetch_array($result);
   if($password!=$row["password"])
   {
    echo"密码错误";
   }
   else {
      echo"登陆成功!";
      exit();
   }
  } 
  }    
?>
Copy after login

3. Database call file conn.php

<?php
/**
* mysql数据库调用
* edit bbs.it-home.org
*/
$link= mysql_connect("localhost","root","123");
 if(!$link)
{
    echo"没连接上";
}
else
{
 $con=mysql_select_db("test");
 if(!$con)
 {
 echo"没连接上test";
 } 
}
?>
Copy after login

That’s it, three simple files to implement PHP user login and simple verification. For those who are new to PHP, it can be used as an introductory reference.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!