Creating a login system in PHP(在 PHP 中创建登录系统)
问题描述
有人可以帮帮我吗?我的用户名是 Blimeo,密码是密码",但是当我输入凭据时,它显示拒绝访问",就像我告诉它的那样.我 100% 确定我的 mySQL 数据库配置正确.
Can someone please help me? My username is Blimeo and my password is "password" but when I put my credentials in, it says "Access denied" like I told it to. I am 100% sure that I configured my mySQL database correctly.
<html>
<body>
<?php
echo sha1('Blimeo');
if (isset($_REQUEST['attempt'])) {
$link = mysql_connect('localhost', 'root', 'password') or die('Could not connect to database');
$user = mysql_real_escape_string($_POST['user']);
$password = sha1(mysql_real_escape_string($_POST['password']));
mysql_select_db('test_users');
$query = mysql_query(
"SELECT user
FROM users
WHERE user = '$user'
AND password = '$password'
") or die(mysql_error());
mysql_fetch_array($query);
$total = mysql_num_rows($query);
if ($total > 0) {
session_start();
$_SESSION['user'] = 'blah';
header('location: dashboard.php');
}
else {
echo '<br>Access denied!';
}
}
?>
<form method="post" action="login.php?attempt">
Enter your username:<input type="text" name="user"/><br/>
Enter your password:<input type="password" name="password"/><br/>
<input type="submit"/>
</form>
</body>
</html>
推荐答案
2016 年更新
请仅使用现有的登录系统,这些系统几乎在每个 PHP 框架中都是开箱即用的!完全没有理由自己写这篇文章,因为用户身份验证是一个很大的话题,编写一个严肃、稳定和现代的登录解决方案需要几个月(几年)的时间.
Please only use existing login systems, which are provided out-of-the-box in nearly every PHP framework! There's absolutly no reason to write this by yourself, as user authentication is a big topic and it will take months (years) to write a serious, stable and modern login solution.
原文,自 2012 年起:
由于登录系统是一个安全问题,每个人都会一遍又一遍地犯同样的错误,我可以清楚地说:
As login systems are a security issue and EVERYBODY makes the same mistakes over and over again, i can clearly say:
使用专业脚本并通过代码来了解发生了什么,什么是散列和加盐以及会话可能会出现什么问题.
Take a professional script and work through the code to understand whats happening, what hashing and salting is and what problems session can have.
[删除过期链接]
以下是您可能需要的三个项目:
Here are three projects that might be what you need:
https://github.com/panique/php-login-one-file
https://github.com/panique/php-login-minimal
https://github.com/panique/huge
这篇关于在 PHP 中创建登录系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中创建登录系统
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01