我有两个php页面.index.php和functions.php。在索引.php中,我调用登录和更改密码函数.php。我的问题是,当我单击登录时,我的登录表单与更改密码表单一起显示。我只想在单击登录时显示更改密码表单。 请帮忙!!
这是我的代码:索引.php
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Login to the site</title>
</head>
<body>
<form action="index.php?act=login" method="post" id= "user_login" >
<center>
<table>
<tr>
<td>User Login</td>
<td><a href="index.php?act=login" >Click Here</a></td>
</tr>
<tr>
<td>Forgot Password?</td>
<td><a href="index.php?act=forgotpassword">Click Here</a></td>
</tr>
</center>
<table>
</form>
<?php
include "functions.php";
$action_type = $_GET["act"];
$form_name = $_GET["name"];
if ($action_type == "login")
{
return login();
}
elseif ($action_type == "forgotpassword")
{
return forgotpassword();
}
elseif ($action_type == "changepassword")
{
return changepassword();
}
?>
</body>
</html>
功能.php:
function login()
{
echo' <script type="text/javascript">
function showhide() {
var form = document.getElementById("login");
if (form.style.visibility == "visible") {
form.style.visibility = "hidden";
}
}
</script>
<form action="index.php?act=login" method="post" id="login" >
<center>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td width="30%" align="right">Username</td>
<td width="70%"><input type="text" name="user" id="text_user"/></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" name="pass" id="text_pass" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="login" name="submit" onsubmit="showhide()" /></td>
</tr>
</center>
</table>
</form> </body></html>';
// login code goes here
}
function changepassword()
{
echo'<form action ="index.php?act=changepassword" method="post" >
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td>Existing Password</td>
<td><input type="password" value="" name="pass" id="text_pass" /></td>
</tr>
<tr>
<td>New Password</td>
<td><input type="password" value="" name="cpass" id="text_cpass"/></td>
</tr>
<tr>
<td>Retype Password</td>
<td><input type="password" value="" name="crepass" id="text_crepass" /></td>
</tr>
<tr>
<td><input type="submit" value="change" name="submit" /></td>
</tr>
</table>
<tr align = "left"> <td><br><a href="index.php?act=logout">LogOut</a></br> </td></tr>
</form>';
// changepassword code goes here
}
?>
我认为你的代码应该是这样的
测试.php
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Login to the site</title>
</head>
<body>
<form action="test.php?act=login" method="post" id= "user_login" >
<center>
<table>
<tr>
<td>User Login</td>
<td><a href="test.php?act=login" >Click Here</a></td>
</tr>
<tr>
<td>Forgot Password?</td>
<td><a href="test.php?act=forgotpassword">Click Here</a></td>
</tr>
</center>
<table>
</form>
<?php
include "functions.php";
if(isset( $_GET["act"])) {
$action_type = $_GET["act"];
if ($action_type == "login")
{
return login();
}
elseif ($action_type == "forgotpassword")
{
return forgotpassword();
}
elseif ($action_type == "changepassword")
{
return changepassword();
}
}
elseif(isset($_GET["name"])) {
$form_name = $_GET["name"];
}
?>
</body>
</html>
和你的函数.php页面
<?php
function login()
{
echo' <script type="text/javascript">
function showhide() {
var form = document.getElementById("login");
if (form.style.visibility == "visible") {
form.style.visibility = "hidden";
}
}
</script>
<form action="index.php?act=login" method="post" id="login" >
<center>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td width="30%" align="right">Username</td>
<td width="70%"><input type="text" name="user" id="text_user"/></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" name="pass" id="text_pass" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="login" name="submit" onsubmit="showhide()" /></td>
</tr>
</center>
</table>
</form> </body></html>';
// login code goes here
}
function changepassword()
{
echo'<form action ="index.php?act=changepassword" method="post" >
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td>Existing Password</td>
<td><input type="password" value="" name="pass" id="text_pass" /></td>
</tr>
<tr>
<td>New Password</td>
<td><input type="password" value="" name="cpass" id="text_cpass"/></td>
</tr>
<tr>
<td>Retype Password</td>
<td><input type="password" value="" name="crepass" id="text_crepass" /></td>
</tr>
<tr>
<td><input type="submit" value="change" name="submit" /></td>
</tr>
</table>
<tr align = "left"> <td><br><a href="index.php?act=logout">LogOut</a></br> </td></tr>
</form>';
}
function forgotpassword()
{
echo'<form action ="index.php?act=changepassword" method="post" >
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td>Existing Password</td>
<td><input type="password" value="" name="pass" id="text_pass" /></td>
</tr>
<tr>
<td>New Password</td>
<td><input type="password" value="" name="cpass" id="text_cpass"/></td>
</tr>
<tr>
<td>Retype Password</td>
<td><input type="password" value="" name="crepass" id="text_crepass" /></td>
</tr>
<tr>
<td><input type="submit" value="change" name="submit" /></td>
</tr>
</table>
<tr align = "left"> <td><br><a href="index.php?act=logout">LogOut</a></br> </td></tr>
</form>';
}
?>
请记住,在您的代码中,您没有声明忘记密码函数,所以我只是复制了更改密码函数并将其重命名为忘记密码函数以给您一个示例
您需要从索引中删除和标签.php
从索引中删除以下两行.php
<form action="index.php?act=login" method="post" id= "user_login" >
和
</form
使用 switch
检查传递的操作并相应地显示表单。
include "functions.php";
$action_type = $_GET["act"];
$form_name = $_GET["name"];
switch($action_type)
{
case 'login':
login();
break;
case 'forgotpassword' :
forgotpassword();
break;
case 'changepassword' :
changepassword();
break;
default :
login();
break;
}
更改代码:
<?php
include "functions.php";
$action_type = $_GET["act"];
$form_name = $_GET["name"];
if ($action_type == "login")
{
return login();
}
elseif ($action_type == "forgotpassword")
{
return forgotpassword();
}
elseif ($action_type == "changepassword")
{
return changepassword();
}
?>
自:
<?php
include "function.php";
$action = isset($_REQUEST['act'])?$_REQUEST['act'] : "";
switch($action)
{
case 'login':
login();
break;
case 'forgotpassword':
changepassword();
break;
}
?>
<form action="index.php?act=login" method="post" id= "user_login" >
将其更改为
<form action="index.php" method="post" id= "user_login" >