dpizd08264 2018-10-22 07:13
浏览 693
已采纳

如何在QNAP(NAS)上使用PHP重定向

I have a NAS (QNAP) where all my files are hosted and the PHP redirect after a user succefully login is not working how it should. This is the code:

<?php
session_start();

$host = "ip:port";
$user = "root";
$password = "admin";
$db = "segnalazioni";
$conn = mysqli_connect($host, $user, $password, $db);
$errore = "Tentativo di accesso non valido";
$errorNoUsername = "Inserire i dati per loggare";

if(isset($_POST['username'])){
    $userUsername = $_POST['username'];
    $userPassword = $_POST['password'];
    $sql = "SELECT * FROM utenti WHERE username='".$userUsername."' AND password = '".$userPassword."'";
    $result = mysqli_query($conn, $sql);

    if(mysqli_num_rows($result)==1){
        $_SESSION['username'] = $userUsername;
        header('location: main.php');
    } else {
        echo $errore;
    }
} else {
    echo $errorNoUsername;
}
?>

The main.php is in the same folder as this page (called login.php) on my NAS. The connection with the DB is working just fine I tested it with an Echo, only the redirect is not working. The same code on my localmachine (and with localhost instead of ip and port) also work just fine and the page manage to redirect me. The issue should be on the file path (i guess) but i don't know how to properly set it. All files are in this folders in this location:

\192.168.x.x\web\Verifiche

Note: When I try the same code on my local machine using xampp (or wamp or anything like that) it works how it should.

  • 写回答

1条回答 默认 最新

  • douhu2525 2018-10-23 09:47
    关注

    For anyone wondering Ih ad some HTML before the php, in this way the redirect wasn't working. Even if I still need to get why on my local machine it was working fine even if I had HTML before it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?