昨天我发布了一个问题,关于我最近上传到实时服务器的登录页面遇到的问题,基本上,页面只是重新加载,没有做任何事情。问题在此供参考:
Login script not working on live server
在看起来永远想要找出问题之后,我不得不将表单发送到另一个页面来运行没有isset的PHP以便弄清楚这一点,并且它工作正常。我找到了造成这个问题的原因,但不明白为什么。
如果没有必要,我不想将我的所有代码从isset更改为其他内容......它可能是不同版本的PHP吗?我的localhost是5.6.15,实时服务器是5.6.13,我认为它不会产生这样的差异。
这里的参考是代码(它也包含在上一个问题中):
<?php
session_start();
$page_title = "Love Deals Login";
require('../inc/connect/config.php');
if($user->is_loggedin()!="") {
header("Location: index.php");
}
if(isset($_POST['login'])) {
$uname = $_POST['txt_uname'];
$upass = $_POST['txt_upass'];
if($user->login($uname,$upass)) {
header("Location: index.php");
} else {
$error = "Login failed. Please try again, or register";
}
}
include('inc/admin-header.php');
?>
<div class="container" style="padding: 100px 0 0 0;">
<div class="form-container">
<form method="post" id="login" action="form-test.php">
<h3>Please login</h3>
<?php if(isset($error)) { ?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php } else if(isset($_GET['joined'])) { ?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-ok"></i> Thanks! You are now registered. You may now login below
</div>
<?php } else if(isset($_GET['pass-update'])) { ?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-ok"></i> Success! Your password has been updated. You may now login below
</div>
<?php } ?>
<div class="form-group col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3 login">
<input type="text" class="form-control" name="txt_uname" placeholder="Username" required />
</div>
<div class="form-group col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3 login">
<input type="password" class="form-control" name="txt_upass" placeholder="Password" required />
</div>
<div class="clearfix"></div>
<div class="form-group col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3 login">
<p class="small text">Forgotten <a href="forgot-user.php">Username</a> / <a href="forgot-pass.php">Password?</a></p>
<button type="submit" name="login" class="btn btn-primary pull-right">
<i class="glyphicon glyphicon-log-in"></i> Login</button>
</div>
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3" style="text-align: center;">
<label>Don't have an account yet? <a href="agree.php">Register now</a></label>
</div>
</form>
</div>
</div>
<?php include('inc/admin-footer.php'); ?>
所有代码都包含在上一个问题中...适用于localhost,但不适用于实时服务器。我也尝试了!empty
和&& !empty
,但没有一个工作,但在isset语句中没有工作在单独的文件中。
答案 0 :(得分:0)
if(isset($_POST['login']))
为:
if(isset($_POST['txt_uname'], $_POST['txt_upass']))
它可以正常工作。