登录脚本在实时服务器上不起作用 [英] Login script not working on live server

查看:81
本文介绍了登录脚本在实时服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机上为一个我已经工作了一段时间的站点构建了一个管理部分,一切都可以在本地主机上正常运行,但是当我将其上传到实时服务器时,它将无法正常工作-并且当我说不会工作时,它什么也不会做!登录页面会按预期加载,如果我尝试不登录而访问index.php页面,它将按照需要将我重定向到login.php,但是当我登录时,它只是重新加载了登录页面,和我去注册时一样.

I have built an admin section on my localhost for a site i have been working on for a while, everything works as it should on my localhost, but when I have uploaded it to a live server, it just wont work - and when i say wont work, it wont do anything! the login page loads as it should, and if i try to access the index.php page without being logged in, it redirects me to login.php, as it should, but when I go to login, it just reloads the login page, and it does the same when I go to register.

我整天都在经历我可能想到的所有可能的错误,我已经对数据库连接,表等,php进行了两次检查,然后再进行了三次检查,我已经回声了"hello world!".从登录页面中包含的各种文件中查看它是否可以正确连接,并且每次都能正常工作...我什至检查了服务器的设置时间,因为我在另一个论坛的某个地方读到有人在类似的问题,他们将服务器更新到正确的时间,并且可以正常工作,与会话有关……但是,似乎没有任何作用.如前所述,它在我的本地主机上运行良好,并且之前我已经在可以工作的实时服务器上尝试登录,但是从那时起,我做了更多的工作.

I've spent the whole day going through every possible error I can think of, I've double and then triple checked the database connection, the tables etc, the php, I've echoed "hello world!" from various files included in the login page to see if it was connecting to them properly, and it works everytime... I've even checked the time the server was set to, as I read somewhere on another forum that someone was having a similar issue, they updated the server to the correct time, and it worked, something to do with the session... but alas, nothing seems to work. As I mentioned before, it works perfectly well on my localhost, and I have already tried the login before on a live server which worked, but since then I have done more work.

供参考,这是我的登录/注册等课程:

for reference, here is my class for login / registration etc:

<?php

class USER {
private $db_user;

function __construct($db) {
    $this->db_user = $db;
}

public function register($clientID,$u_fname,$u_lname,$u_tel,$u_email,$uname,$upass,$secQuestion,$secAnswer) {

    try {

        $new_password = password_hash($upass, PASSWORD_DEFAULT);

        $stmt = $this->db_user->prepare("INSERT INTO users(client_id,user,pass,first_name,last_name,telephone,email,sec_question,sec_answer) VALUES(:client,:user, :pass, :fname, :lname, :tel, :email, :secQ, :secA)");

        $stmt->bindparam(":user", $uname);
        $stmt->bindparam(":client", $clientID);
       $stmt->bindparam(":pass", $new_password);
       $stmt->bindparam(":email", $u_email);
       $stmt->bindparam(":fname", $u_fname);
       $stmt->bindparam(":lname", $u_lname);
       $stmt->bindparam(":tel", $u_tel);
       $stmt->bindparam(":secQ", $secQuestion);
       $stmt->bindparam(":secA", $secAnswer);          
       $stmt->execute();

       return $stmt;
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
}

public function login($uname, $upass) {

    try {

        $stmt = $this->db_user->prepare("SELECT * FROM users WHERE user=:user LIMIT 1");
        $stmt->execute(array(':user'=>$uname));
        $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
        if($stmt->rowCount() > 0) {
            if(password_verify($upass, $userRow['pass'])) {
                $_SESSION['user_session'] = $userRow['id'];
                return true;
            } else {
                return false;
            }
        }
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
}

public function is_loggedin() {
    if(isset($_SESSION['user_session'])) {
        return true;
    }
}

public function logout() {
    session_destroy();
    unset($_SESSION['user_session']);
    return true;
}
}
?>

我的配置文件:

<?php 

require('constants.php');

try {
$db = new PDO("mysql:host=" . DB_SERVER . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$db->exec("SET NAMES 'utf8'");
} catch (PDOException $e) {
echo "Could not connect to the database because: " . $e->getMessage();
exit;
}

include_once 'class.user.php';
$user = new USER($db);
?>

和我的登录页面本身:

<?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">
        <h3>Please login</h3>
        <?php if(isset($error)) { ?>
            <div class="alert alert-danger">
                <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?>
            </div>
        <?php } else if(isset($_GET['joined'])) { ?>
                <div class="alert alert-info">
                    <i class="glyphicon glyphicon-ok"></i> &nbsp; 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> &nbsp; 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>&nbsp;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'); ?>

有什么想法可能阻止我的脚本运行?甚至只是将我指向正确的方向,将不胜感激!

any ideas what could be preventing my script from running? Or even just point me in the right direction, that would be greatly appreciated!

推荐答案

尝试!empty()而不是isset().

Try !empty() instead of isset() .

这篇关于登录脚本在实时服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆