在我所有的页面中,我都有一个文本按钮,如果单击该按钮,它将在弹出div中显示登录表单.如果用户重新加载页面,此弹出的div将自动关闭.
现在,我在config.PHP文件中有一个函数作为登录名的配置.如果登录失败,则在下面或登录表单的底部,将显示一条通知,指出“登录失败”.
问题是因为仅当用户单击页面中的“登录”按钮时才会显示此登录表单,因此当它重定向回时,它不会自动告诉用户他/她是否登录失败.用户必须再次单击登录按钮才能知道登录是否失败.
<p><?PHP if($_GET['result']=='Failed'){echo 'invalid login';}?></p>
这是登录框的完整代码,用户必须单击登录按钮以显示登录表单的弹出div:
<li>
<a href = "javascript:void(0)"
onclick ="document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'">Login</a></li>
</ul>
<!--Black Overlay-->
<div id="fade" class="black_overlay" onl oad="initDynamicoptionLists()"></div>
<!--Pop Up Div-->
<div id="light" class="white_content">
<div id="loginBox">
<span id="login-form">Login</span>
<form method="post" action="config-login.PHP">
<table width="345" align="center" style="background:honeydew; vertical-align:top; margin:0px auto; border:solid medium yellowgreen;">
<tr>
<td class="myimage">Email :</td>
<td width="196" style="padding-right:2px;"><input type="text" name="member_email" style="width:100%"/></td></tr>
<tr>
<td class="myimage">Password : </td>
<td style="padding-right:2px;"><input type="password" name="member_password" style="width:100%"/></td></tr>
</table>
<div style="background:greenyellow; display:block; width:100%; overflow:hidden; margin:10px 0; padding:10px 0;">
<input type="hidden" name="return" value="<?PHP echo $_SERVER['REQUEST_URI']; ?>" />
<p><?PHP
if($_GET['result']=='Failed'){
echo 'invalid login';
}?>
</p>
<input class="myimage" style="margin-right:10px; padding:0 10px; float:right;" type="submit" value="Login"/>
<span style="position: absolute; top: 11px; right:1px; color:white;" id="closeBlocked">
<a style="color:green; text-decoration:none; background:white; padding:10px;"
href = "javascript:void(0)"
onclick ="document.getElementById('light').style.display='none';
document.getElementById('fade').style.display='none'"><b>X</b></a></span>
</div>
</form>
</div>
</div>
<!-- End of Pop Up Div-->
<?PHP
session_start();
// include connection file
include("configPDO.PHP");
$member_email=$_POST['member_email'];
$member_password=$_POST['member_password'];
$return = MysqL_real_escape_string($_POST['return']);
$STM = $dbh->prepare("SELECT * FROM customer WHERE member_email = :member_email AND member_password = :member_password");
$STM->bindParam(':member_email', $member_email);
$STM->bindParam(':member_password', $member_password);
$STM->execute();
$count = $STM->rowCount();
$row = $STM -> fetch(PDO::FETCH_ASSOC);
if ( $count == 1 ) {
session_start();
$_SESSION['login_id'] = $row['member_id'];
$_SESSION['member_name'] = $row['member_name']; // added
$_SESSION['member_email'] = $row['member_email']; // added
//echo 'SESSION =' .$_SESSION['myusername'];
//echo 'ROW =' .$row['myusername'];
//var_dump($row);
if ( $_SESSION['login_id'] != '' || $_SESSION['login_id'] > 0 ) { // edited
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
} else {
header("location:index.PHP"."?result=Failed");
}
}
else
{
header("location:index.PHP"."?result=Failed");
}
$dbh = null;
?>
解决方法:
您可以借助您的get变量实现此目标
只需添加ID
<a href = "javascript:void(0)"
onclick ="document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'">Login</a>
like
<a id="popmeup" href = "javascript:void(0)"
onclick ="document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'">Login</a>
and put code at the end of document before end of body tag
<?PHP
if($_GET['result']=='Failed'){ ?>
<script type="text/javascript">
document.getElementById('popmeup').click();
</script>
<?PHP }?>