Home  >  Article  >  Backend Development  >  How to implement PHP login without using a database

How to implement PHP login without using a database

藏色散人
藏色散人Original
2021-11-29 09:08:572852browse

How to implement PHP login without a database: 1. Create an index.php file; 2. Create a form login form; 3. Pass "if($user=='user' && $pwd==' pwd'){...}" method can be used to determine the user's login.

How to implement PHP login without using a database

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3.

How to implement php login without using a database?

php does not need a database to design the login interface

POST the account and password directly to another PHP for acceptance.

index.php

<form name="form1" method="post" action="confirm.php">
<p>用户名:<input type="text" name="user"></p>
<p>密码:<input type="password" name="pwd"></p>
<p><input type="submit" ></p>
</form>

confirm.php

<?php
$user = isset($_POST[&#39;user&#39;])? $_POST[&#39;user&#39;] : &#39;&#39;;
$pwd = isset($_POST[&#39;pwd&#39;])? $_POST[&#39;pwd&#39;] : &#39;&#39;;
if(empty($user) || empty($pwd)){
echo &#39;用户名和密码不能为空&#39;;
exit();
}
if($user==&#39;user&#39; && $pwd==&#39;pwd&#39;){
echo &#39;登陆成功&#39;;
}else{
echo &#39;用户名或密码错误&#39;;
}
?>

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to implement PHP login without using a database. For more information, please follow other related articles on the PHP Chinese website!

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