请帮助 - PHP登录表单 [英] Please help - PHP login form

查看:63
本文介绍了请帮助 - PHP登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人能够解释为什么错误消息不会显示在登录表单上但显示在页面的左上角。我是PHP的新手,并且不明白为什么会发生这种情况,因为我可以告诉代码是在正确的位置。我已经在互联网上寻找类似的问题,但可以找到任何人可以帮助我确定我的问题



login.php

I was wondering if someone would be able to explain why the error messages wont display on the login form but display in the top left corner of the page. I'm pretty new to PHP and don't understand why this is happening as far as I can tell the code is in the correct place. i have looked all over the internet for similar problems but can fin any could someone please help me to determine my problem

login.php

<?php
session_start();
if (isset($_SESSION['logged_in'])){
	header('location:./index.php?msg=6');
} else {//ELSE FOR (isset($_SESSION['logged_in']))
	require_once('./config.php');
	require_once('./includes/functions.php');
	$msgid = 5;//MESSAGE ID VARIABLE
	//THE LOGIN FORM 

	$form = '

		<html>
			<head>
				<link rel="stylesheet" href="css/login.css" type="text/css"/>
			</head>
			<body>

				<form class="login" action="" method="post">
				    <p class="clearfix">
				        <label for="login">Username</label>
				        <input type="text" name="user" id="login" placeholder="Username">
				    </p>
				    <p class="clearfix">
				        <label for="password">Password</label>
				        <input type="password" name="password" id="password" placeholder="Password"> 
				    </p>
				    <p class="clearfix">
				        <input type="checkbox" name="remember" id="remember">
				        <label for="remember">Remember me</label>
				    </p>
				    <p class="clearfix">
				        <input type="submit" name="submit" value="Login">
				    </p>
				    '; 
if (isset($_Get['msg']) or $msgid !== 0){
   	$form .= '<p class="clearfix">
		        <label for="msg">';  
		        getlogmsg($msgid); 
    $form .= '</label>
			    </p>';
}
    $form .= '  
				</form>
			</body>
		</html>
	';
if ($_POST){


	$username = $_POST['user'];
	$password = $_POST['password'];


		if($username && $password){
		
			$connect = mysql_connect(db_host, db_user, db_pass) or die ('unable to connect to server');//CONECTING TO THE MYSQL SERVER
			mysql_select_db(db_name, $connect) or die ('unable to connect to database');//SELECTING THE DB
			$query = mysql_query("SELECT * FROM users WHERE user='$username'");//SETTING UP THE QUERY
			$numrows = mysql_num_rows($query);//SETTING NUMROWS == TO NUMBER OF ROWS IN DB WHERE QUERY TRUE
			
				if ($numrows != 0){//CHECKING THAT THE USER EXISTS
					
					while($row = mysql_fetch_assoc($query)){
					
						$dbusername = $row['user'];
						$dbpassword = $row['password'];
						$dbemail = $row['email'];
						$dbign = $row['ign'];
						$dbactive = $row['active'];
						$dbbanned = $row['banned'];
						$dbbanreason = $row['banned_reason'];
						$dbaccounttype = $row['account_type'];
						
					}//END OF WHILE
						
						if($username == $dbusername && md5($password) == $dbpassword){

							if($dbactive == 1){
								$_SESSION['logged_in']=$username;
								header('location:./index.php');
							} else {//ELSE FOR ($dbactive == 1)
								$msgid = 7;//SET THE MESSAGE ID TO 7 (ACCOUNT NOT ACTIVATED YET - REFFER TO FUNCTIONS.PHP)
								die($form);//KILL EXECUTION OF CODE AND DISPLAY FORM
							}//END OF IF($dbactive == 1)

						} else {//ELSE FOR ($username == $dbusername && md5($password) == $dbpassword)
							$msgid = 5;//SET THE MESSAGE ID TO 5 (WRONG USERNAME OR PASSWORD - REFFER TO FUNCTIONS.PHP)
							die($form);//KILL EXECUTION OF CODE AND DISPLAY FORM
						}//END OF IF($username == $dbusername && md5($password) == $dbpassword)

				} else {//ELSE FOR ($numrows != 0)
				 $msgid = 4;//SET THE MESSAGE ID TO 4 (NO USER ACCOUNT - REFFER TO FUNCTIONS.PHP)
				 die($form);//KILL EXECUTION OF CODE AND DISPLAY THE FORM
				}//END OF IF($numrows != 0)

			echo $form;//ECHO FORM IF USERNAME AND PASSWORD WAS SENT TO SERVER BUT 
		} else {//ELSE FOR ($username && $password)
			echo $form;//ECHO FORM IF NO USERNAME OR PASSWORD WERE SENT WITH REQUEST
		}//END OF IF($username && $password

} else {//ELSE FOR ($_POST)

	echo $form;//DISPLAY FORM IF NO POST DATA WAS FOUND

}//END OF IF($_POST)

}//END OF IF(isset($_SESSION['logged_in']))
?>




Functions.php




Functions.php

<?php

	function getlogmsg($msgid)
	{
		
		if($msgid=='1') {
		print'Could not connect to the MySQL service';
	} elseif ($msgid=='2') {
		print'Could not connect to the database';
	} elseif ($msgid=='3') {
		print'Could not connect to the database table';
	} elseif ($msgid=='4') {
		print'We could not find this user account';
	} elseif ($msgid=='5') {
		print'Wrong username or password';
	} elseif ($msgid=='6') {
		print'Successfully logged out';
	} elseif ($msgid=='7') {
		print'Account not activated yet';
	}

	}
?>





Login.css



Login.css

/* GLOBALS */

body{
    background:url("../img/backgrounds/BG.jpg") repeat;/*setting the background image*/
}

*,
*:after,
*:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

/* FORM */

.login {
    font-family: 'Ubuntu', 'Lato', sans-serif;
    font-weight: 400;
    /* Size and position */
    width: 300px;
    position: relative;
    margin: 60px auto 30px;
    padding: 10px;
    overflow: hidden;

    /* Styles */
    background: #111; 
    border-radius: 0.4em;
    border: 1px solid #191919;
    box-shadow: 
        inset 0 0 2px 1px rgba(255,255,255,0.08), 
        0 16px 10px -8px rgba(0, 0, 0, 0.6);
}

.login label {
    /* Size and position */
    width: 50%;
    float: left;
    padding-top: 9px;

    /* Styles */
    color: #ddd;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 1px 0 #000;
    text-indent: 10px;
    font-weight: 700;
    cursor: pointer;
}

.login input[type=text],
.login input[type=password] {
    /* Size and position */
    width: 50%;
    float: left;
    padding: 8px 5px;
    margin-bottom: 10px;
    font-size: 12px;

    /* Styles */
    background: #1f2124; /* Fallback */
    background: -moz-linear-gradient(#1f2124, #27292c);
    background: -ms-linear-gradient(#1f2124, #27292c);
    background: -o-linear-gradient(#1f2124, #27292c);
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#1f2124), to(#27292c));
    background: -webkit-linear-gradient(#1f2124, #27292c);
    background: linear-gradient(#1f2124, #27292c);    
    border: 1px solid #000;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.1);
    border-radius: 3px;

    /* Font styles */
    font-family: 'Ubuntu', 'Lato', sans-serif;
    color: #fff;

}

.login input[type=text]:hover,
.login input[type=password]:hover,
.login label:hover ~ input[type=text],
.login label:hover ~ input[type=password] {
    background: #27292c;
}

.login input[type=text]:focus, 
.login input[type=password]:focus {
    box-shadow: inset 0 0 2px #000;
    background: #494d54;
    border-color: #51cbee;
    outline: none; /* Remove Chrome outline */
}

.login p:nth-child(3),
.login p:nth-child(4) {
    float: left;
    width: 50%;
}

.login label[for=remember] {
    width: auto;
    float: none;
    display: inline-block;
    text-transform: capitalize;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0px;
    text-indent: 2px;
}

.login input[type=checkbox] {
    margin-left: 10px;
    vertical-align: middle;
}

.login input[type=submit] {
    /* Width and position */
    width: 100%;
    padding: 8px 5px;
  
    /* Styles */
    border: 1px solid #0273dd; /* Fallback */
    border: 1px solid rgba(0,0,0,0.4);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 10px 10px rgba(255,255,255,0.1);
    border-radius: 3px;
    background: #38a6f0;
    cursor:pointer;
  
    /* Font styles */
    font-family: 'Ubuntu', 'Lato', sans-serif;
    color: white;
    font-weight: 700;
    font-size: 15px;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.8);
}

.login input[type=submit]:hover { 
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}

.login input[type=submit]:active { 
    background: #287db5;
    box-shadow: inset 0 0 3px rgba(0,0,0,0.6);
    border-color: #000; /* Fallback */
    border-color: rgba(0,0,0,0.9);
}

.no-boxshadow .login input[type=submit]:hover {
    background: #2a92d8;
}

.login:after {
    /* Size and position */
    content: "";
    height: 1px;
    width: 33%;
    position: absolute;
    left: 20%;
    top: 0;

    /* Styles */
    background: -moz-linear-gradient(left, transparent, #444, #b6b6b8, #444, transparent);
    background: -ms-linear-gradient(left, transparent, #444, #b6b6b8, #444, transparent);
    background: -o-linear-gradient(left, transparent, #444, #b6b6b8, #444, transparent);
    background: -webkit-gradient(linear, 0 0, 100% 0, from(transparent), color-stop(0.25, #444), color-stop(0.5, #b6b6b8), color-stop(0.75, #444), to(transparent));
    background: -webkit-linear-gradient(left, transparent, #444, #b6b6b8, #444, transparent);
    background: linear-gradient(left, transparent, #444, #b6b6b8, #444, transparent);
}

.login:before {
    /* Size and position */
    content: "";
    width: 8px;
    height: 5px;
    position: absolute;
    left: 34%;
    top: -7px;
    
    /* Styles */
    border-radius: 50%;
    box-shadow: 0 0 6px 4px #fff;
}

.login p:nth-child(1):before{
    /* Size and position */
    content:"";
    width:250px;
    height:100px;
    position:absolute;
    top:0;
    left:45px;

    /* Styles */
    -webkit-transform: rotate(75deg);
    -moz-transform: rotate(75deg);
    -ms-transform: rotate(75deg);
    -o-transform: rotate(75deg);
    transform: rotate(75deg);
    background: -moz-linear-gradient(50deg, rgba(255,255,255,0.15), rgba(0,0,0,0));
    background: -ms-linear-gradient(50deg, rgba(255,255,255,0.15), rgba(0,0,0,0));
    background: -o-linear-gradient(50deg, rgba(255,255,255,0.15), rgba(0,0,0,0));
    background: -webkit-linear-gradient(50deg, rgba(255,255,255,0.15), rgba(0,0,0,0));
    background: linear-gradient(50deg, rgba(255,255,255,0.15), rgba(0,0,0,0));
    pointer-events:none;
}

.no-pointerevents .login p:nth-child(1):before {
    display: none;
}

推荐答案

_SESSION['logged_in'])){
\theader('location:./index.php?msg=6');
} else {//ELSE FOR (isset(
_SESSION['logged_in'])){ header('location:./index.php?msg=6'); } else {//ELSE FOR (isset(


_SESSION['logged_in']))
\trequire_once('./config.php');
\trequire_once('./includes/functions.php');
\t
_SESSION['logged_in'])) require_once('./config.php'); require_once('./includes/functions.php');


msgid = 5;//MESSAGE ID VARIABLE
\t//THE LOGIN FORM

\t
msgid = 5;//MESSAGE ID VARIABLE //THE LOGIN FORM


这篇关于请帮助 - PHP登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆