任何人都可以帮我解决这个问题吗? 我需要一个简单的登录页面,并有2个文件。检查用户名和密码后,它应该重定向到index1.php页面,这是我的头部旋转。我做不到。任何人都可以看到我应该在我的代码中加入什么内容?
login.function.php
?php
session_start();
function login($username, $password)
{
//Correct u and pw
$correct_user = "Admin";
$correct_pass = "test";
//Step 1
if ( !empty($username) && !empty($password) )
{
//Step 2
if ( $username == $correct_user
&& $password == $correct_pass )
{
//Step3
$_SESSION['user_login'] = TRUE;
}
//If u or pw is false
else
{
return "bla bla bla...";
}
}
//If user or pw is empty
{
return "You have to give u and pw.";
}
}
/*********************************************
* to log out
*********************************************/
function logout()
{
$_SESSION['user_login'] = FALSE;
session_destroy();
}
/**********************************************************
*********************************************************/
function is_logon()
{
if ( isset($_SESSION['user_login'])
&& $_SESSION['user_login'] == TRUE )
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
这是在sucessfull登录重定向到index1.php文件后应该的index.php文件
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My page</title>
</head>
<body>
<table width="100%" border="1">
<tbody>
<tr>
<td> </td>
</tr>
<tr>
<td align="center"><form action="" method="post">
User:<br>
<input type="text" name="username"><br>
Password:<br>
<input type="password" name="password"><br>
<input type="hidden" name="login_form" value="1">
<input type="submit" value="Logga in">
</form></td>
</tr>
<tr>
<td> </td>
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:0)
FROM alpine:3.4
RUN apk update && apk add curl vim git
应为<form action="">
,因为这会将用户发送到带有POST请求的index1.php。
答案 1 :(得分:-1)
表单方法和操作应该是这样的
<form method="post" action="login.function.php">
在将 user_login 会话设置为true后的第3步中,您应该使用
将用户重定向到 index1.php 文件 header('Location: http://www.example.com/index1.php');
然后,您应该在 index1.php 文件的开头检查 user_login 会话,如果设置为false,则将用户重定向到登录页面。