如何在php中创建登录系统?

时间:2015-01-29 20:57:05

标签: php login login-script

很抱歉我这是一个新手,而且这个网站主要面向专业程序员。但我来自一家公司,我需要认真的帮助。我看了如何创建一个登录脚本。我运行了登录,点击提交后,我的代码显示的页面显示并且代码没有运行。我需要您关于创建登录脚本以及如何使其工作的建议。解释而不是链接会有所帮助。

<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Quicksand:400,700' rel='stylesheet' type='text/css'>
<link href="logincss.css" rel='stylesheet' type='text/css'>
</head>

<body>
<div class="login">
<h1 class="logintitle">Login to Phantoms </h1>

<form method="post" action="checklogin.php" name="login">
  <center><input type="username" name="username" placeholder="Username" id="username" required="required" minlength="4" maxlength="30"></center>

  <center><input type="password" name="password" placeholder="Password" id="password" required="required" minlength="3" maxlength="20"></center>

  <center><input type="submit" name="login" id="loginsubmit" value="Login to Phantoms">
</form>

<div class="options">
<a href="#" class="register">Register</a>
<a href="#" class="passwordrecovery">Forgot Username or Password</a>



</form> 
</div>

**指向checklogin脚本的链接:http://justpaste.it/j5l8

**

1 个答案:

答案 0 :(得分:2)

你写的相当基本的脚本但它可以工作。 虽然

在你的剧本中看起来很奇怪
session_register("myusername");
session_register("mypassword"); 

您可以使用这样的函数来注册会话,在新列session_ID下的用户表中的数据库中存储会话ID,添加另一列last_activebrowser_information(用户代理) ),ip来存储用户的IP。

每个页面加载函数(例如(bool) check_session($session_id))需要调用以检查所有session_IDbrowser_informationip是否仍然匹配。

简要介绍了如何为新功能编写代码,不是StackOverflow为您编写代码的工作,我希望有所帮助!

编辑:正如我在评论中所建议的,这个答案应该延长。

Fred -ii - 建议使用mysqli with prepared statementsPDO with prepared statements.进行密码存储,使用CRYPT_BLOWFISH或PHP 5.5&#39; {{3}功能。对于PHP&lt; 5.5使用password_hash()