我在右上角的标题中做了一个登录表单,其他内容如搜索栏和 Logo
我有一个计划,当我登录时,其他标题内容保持不变,但只有登录内容更改为登录内容
这是我认为完全没有问题的代码
PHP代码
if(empty($_POST) === false){
$username = $_POST['input-username'];
$password = $_POST['input-password'];
if(empty($username) === true || empty($password) ===true){
$errors[] = 'You Need To Enter a Username And a Password';
}
else if(user_exists($username) === false){
$errors[] = 'We Can\'t Find That Username';
}
else{
$login = login($username, $password);
if($login === false){
$errors[] = 'Your Username and Password Combination is Incorrect';
}
else{
$_SESSION['user_id'] = $login;
header("Location: index.php");
}
}
print_r($errors);
}
HTML 脚本
<form method="post" action="index.php" name="signin-form">
<table border="1">
<tr>
<td>Username</td><td><input type="text" name="input-username" id="input-username"></td>
<td>Password</td><td><input type="password" name="input-password" id="input-password"></td>
<td>
<input type="submit" name="sign-in" id="sign-in" value="Log in">
</td>
</tr>
<tr>
<td colspan="2">
<input type="checkbox" name="remember-me">
<label id="information">Keep Me Eating Picture</label>
</td>
<td colspan="2">
<a href="#" id="forgotpass">Forgotten My Username or Password</a>
</td>
</tr>
</table>
</form>
但不知何故情况变得奇怪 输入用户名和密码后,为什么我要在登录内容中点击提交按钮两次以重定向到登录内容?
像这样:用户名 obink 密码 obink 并输入
第一次登录 没有任何反应但是用户名字段和密码字段为空 第二次登录 用户名和密码空白处是将登录内容重定向到已登录内容的时候
是我的代码出了问题还是什么?我曾尝试重建 CSS,但没有任何反应。噢,我已经有了用户功能页面,它是存储我需要的任何功能的页面
这里或多或少是标题内容设计:
div 标志
div 搜索框
和div用户这样登录还是不登录
if (logged_in($user_data['user_id']) === false){
include 'login.php';
}
else{
include 'logged_in.php';
}
全部向左浮动
和用户函数中的php
function logged_in(){
return (isset($_SESSION['user_id'])) ? true : false;
}
在我的 source.php 页面中
if(logged_in() === true)
{$sid = $_SESSION['user_id'];
$user_data = user_data($_SESSION['user_id'], 'user_id', 'username', 'password', 'firstname', 'lastname', 'email');
}
更新我的标题的条件 标题上的 html
<div id="header">
<div id="header-content">
<div id="logo">
<a href="index.php" style="text-decoration:none;">
logo</a>
</div>
<div id="searchbox">
<input type="text" placeholder="Search" size="50">
</div>
标题中间的php
if(empty($_SESSION['user_id'])){
include 'includes/widgets/login.php';
}
else{
include 'includes/widgets/loggedin.php';
}
关闭div
</div>
</div>
抱歉我的英语不好
最佳答案
试试这段代码:
<?php
session_start();
if(empty($_SESSION['user_id'])){
?>
<form method="post" action="index.php" name="signin-form">
<table border="1">
<tr>
<td>Username</td><td><input type="text" name="input-username" id="input-username"></td>
<td>Password</td><td><input type="password" name="input-password" id="input-password"></td>
<td>
<input type="submit" name="sign-in" id="sign-in" value="Log in">
</td>
</tr>
<tr>
<td colspan="2">
<input type="checkbox" name="remember-me">
<label id="information">Keep Me Eating Picture</label>
</td>
<td colspan="2">
<a href="#" id="forgotpass">Forgotten My Username or Password</a>
</td>
</tr>
</table>
</form>
<?php
} else {
echo "Logged in! <a href='logout.php'>Logout</a>";
//You can display the users name here; Example: echo "Hi, ".$user_data['name'];
}
?>
PHP 脚本:
<?php
if(empty($_POST) === false){
$username = $_POST['input-username'];
$password = $_POST['input-password'];
if(empty($username) === true || empty($password) ===true){
$errors[] = 'You Need To Enter a Username And a Password';
}
else if(user_exists($username) === false){
$errors[] = 'We Can\'t Find That Username';
}
else{
$login = login($username, $password);
if($login === false){
$errors[] = 'Your Username and Password Combination is Incorrect';
}
else{
$_SESSION['user_id'] = $login;
header("Location: index.php");
}
}
print_r($errors);
}
?>
这将解决您的登录问题
关于php - 右上角标题内容上的登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18654792/