• User

    Php-Header-Dreamweaver cs3

    Salve dopo un ennesimo tentativo di risolvere un problema di "header" non mi resta che chiedere aiuto agli utenti di questo forum visto che sono tre mesi che ci provo senza risultati; ossia ho creato una pagina index di cui ho integrato un box di login, ma ogni volta che provo il form questo non mi reindirizza alla pagina voluta ma bensì ritorna alla index mostrandomi un errore sugli "header". Chiedo cortesemente se qualcuno mi può aiutare a riscrivere il form per evitare l'errore. Posto qui il codice:
    (NB: devo informarVi che sono piuttosto negato in Php e, se non vi dispiace, dove dovrei mettere le modifiche esattamente nel codice sottostante)

    <?php session_start();?>
    <?php virtual('/Connections/conn.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }
    ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
    session_start();
    }

    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset($_POST['Username'])) {
    $loginUsername=$_POST['Username'];
    $password=$_POST['Password'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "/utente/login_ok.php";
    $MM_redirectLoginFailed = "/utente/error_login.php";
    $MM_redirecttoReferrer = false;
    mysql_select_db($database_conn, $conn);

    $LoginRS__query=sprintf("SELECT username, user_password FROM utenti WHERE username=%s AND user_password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

    $LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
    $loginStrGroup = "";

    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;

    if (isset($_SESSION['PrevUrl']) && false) {
    $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
    header("Location: ". $MM_redirectLoginFailed );
    }
    }
    ?>
    <------- da qui parte il codice HTML------->
    <!DOCTYPE .....................w3.org/1999/xhtml">
    <head>
    <---escludo questo pezzo in quanto non importante per la risoluzione --->
    </div>
    <div id="Internal_login_b">
    <form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
    <table width="330" align="center">
    <tr>
    <td scope="col"><span class="Stile4">
    <label for="Username"><strong>Username</strong></label>
    </span></td>
    <td><input name="Username" type="text" id="Username" maxlength="20" /></td>
    </tr>
    <tr>
    <td scope="col"><label for="Password"><span class="Stile3">Password</span></label></td>
    <td><input name="Password" type="password" id="Password" maxlength="20" /></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" name="button" id="button" value="Login" />
    </div></td>
    </tr>
    </table>
    </form>
    </div>

    Grazie in anticipo del Vostro aiuto.
    By Arkom


  • User Attivo

    Ciao,
    presumo che l'errore che ti segnala è la presnza di un output precedente al tentativo di eseguire il redirect.
    Il motivo è che questa porzione di codice:
    [PHP]
    <?php session_start();?>
    <?php virtual('/Connections/conn.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    ...
    [/PHP]
    genera un output, ovvero due "ritorno a capo", uno ciascuno dopo la chiusura dei tag php ?>
    Modifica così:
    [PHP]
    <?php session_start();
    virtual('/Connections/conn.php');
    if (!function_exists("GetSQLValueString")) {
    ...
    [/PHP]
    o così:
    [PHP]
    <?php session_start();?><?php virtual('/Connections/conn.php'); ?><?php
    if (!function_exists("GetSQLValueString")) {
    ...
    [/PHP]

    La prima soluzione è decisamente migliore.
    Inoltre verifica che Connections/conn.php non generi un output.

    Alessandro