虽然我能够使用它,但我并不是特别懂PHP。不幸的是,当我使用此代码登录时,它只是将我重新定向到页面并且不会登录。事实上,我知道它至少可以与MySQL数据库一起使用,因为我有一个可用的注册页面。
我在使用PHP5.4和Apache2.4的Linux服务器上运行它。
感谢您的帮助!
<?php
mysql_connect("localhost", "REDACTED", "REDACTED") or die(mysql_error());
mysql_select_db("renew2_mysql") or die(mysql_error());
if(isset($_COOKIE['ID_renew_computers'])){
$username = $_COOKIE['ID_renew_computers'];
$pass = $_COOKIE['Key_renew_computers'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: members.php");
}
}
}
if (isset($_POST['submit'])) {
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}else{
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_renew_computers, $_POST['username'], $hour);
setcookie(Key_renew_computers, $_POST['pass'], $hour);
header("Location: index.php");
}
}
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>Renew Computers</title>
<link href='http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto:100' rel='stylesheet' type='text/css'>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
function getCookie(c_name){
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
function setCookie(c_name,value,time){
document.cookie = c_name + "=" +escape(value);
}
function eraseCookie(cookie_name){
setCookie(cookie_name,"",-1);
}
$(document).ready(function(){
setInterval(function(){$('#data').focus()},20);
if(getCookie("err") == 1){
$('.login-container').css({marginTop:'-60px',opacity:'1'});
$('.login-container').effect("shake");
alert("Invalid Card");
eraseCookie("err");
}else{
setTimeout(function(){$('.login-container').animate({marginTop:'-60px',opacity:'1'},500);},500);
}
});
</script>
<style>
.background{
position:fixed;
top:-100px;
left:-100px;
right:-100px;
bottom:-100px;
background-image:url('http://renewcomputers.com/data/uploads/renewfront.png');
-webkit-filter: blur(10px);
filter: blur(10px);
background-size:cover;
}
.login-container{
position:fixed;
top:50%;
left:50%;
margin-top:-20px;
margin-left:-150px;
height:290px;
width:300px;
background-color:#dddddd;
padding:0;
opacity:0;
}
.login-header{
width:300px;
height:50px;
border-bottom: 1px solid #56af79;
background-color: #6ac48e;
font-family: 'Roboto', sans-serif;
border-bottom: 1px solid #56af79;
color:white;
text-decoration:none;
font-size:22pt;
line-height:50px;
}
.login-header-border{
border-right: 1px solid #56af79;
box-shadow: 1px 0 0 rgba(255, 255, 255, 0.3);
}
.login-form{
height:200px;
width:260px;
padding:20px;
font-family: 'Roboto', sans-serif;
}
.login-form-input{
}
.login-form-button{
}
.login-form{
height:200px;
width:260px;
padding:20px;
font-family: 'Roboto', sans-serif;
}
.login-form-input{
width:100%;
-webkit-appearance: none;
appearance: none;
display: inline-block;
height: 29px;
margin: 0;
padding: 0 8px;
background: #fff;
border: 1px solid #c8c8c8;
border-top: 1px solid #c0c0c0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-border-radius: 1px;
-moz-border-radius: 1px;
border-radius: 1px;
font-family: 'Roboto', sans-serif;
}
.login-form-input:hover{
border: 1px solid #b9b9b9;
border-top: 1px solid #a0a0a0;
-webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
-moz-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.login-form-input:focus{
outline:none;
}
.login-form-button{
height:30px;
width:70px;
border: 1px solid #3079ed;
color: #fff;
text-shadow: 0 1px rgba(0,0,0,0.1);
background-color: #4d90fe;
background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#4787ed));
background-image: -webkit-linear-gradient(top,#4d90fe,#4787ed);
background-image: -moz-linear-gradient(top,#4d90fe,#4787ed);
background-image: -ms-linear-gradient(top,#4d90fe,#4787ed);
background-image: -o-linear-gradient(top,#4d90fe,#4787ed);
background-image: linear-gradient(top,#4d90fe,#4787ed);
border-radius:2px;
}
.login-form-button:hover{
border: 1px solid #2f5bb7;
color: #fff;
text-shadow: 0 1px rgba(0,0,0,0.3);
background-color: #357ae8;
background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#357ae8));
background-image: -webkit-linear-gradient(top,#4d90fe,#357ae8);
background-image: -moz-linear-gradient(top,#4d90fe,#357ae8);
background-image: -ms-linear-gradient(top,#4d90fe,#357ae8);
background-image: -o-linear-gradient(top,#4d90fe,#357ae8);
background-image: linear-gradient(top,#4d90fe,#357ae8);
}
</style>
</head>
<body>
<div class="background"></div>
<div id="login" class="login-container">
<div class="login-header">
Renew Computers
</div>
<div class="login-form">
<form action="login.php" method="post">
Username:<div style="height:10px;"></div>
<input type="text" name="username" placeholder="Username" class="login-form-input"/><br /><br />
Password:<div style="height:10px;"></div>
<input type="password" name="pass" placeholder="Password" class="login-form-input"/><br /><br />
<input type="submit" class="login-form-button"/>
<input type="hidden" name="type" value="login"/>
</form>
</div>
<!--<div class="login-form">
<form method="post" action="process.php">
<div align="center">Please Swipe Your Card</div><div style="height:10px;"></div>
<input type="text" name="data" placeholder="" style="cursor:default;" autocomplete="off" id="data" class="login-form-input"/><br /><br />
<input type="submit" class="login-form-button"/>
<input type="hidden" name="type" value="login"/>
</form>
</div>-->
</div>
</body>
</html>
<?php
}
?>
答案 0 :(得分:0)
根据评论我的代码使用了不安全,错误和过时的做法。我选择使用更新,更好的新系统。感谢所有帮助!