phphttp-redirectnasqnap

How to redirect with PHP on a QNAP (NAS)


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.


Solution

  • 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.