Visualizzazione dei risultati da 1 a 6 su 6

Discussione: redirect in php

  1. #1

    redirect in php

    ciao a tutti,
    so che questo argomento è stato gia trattato sul forum ma nessuna delle soluzioni proposte si adattava al mio caso. Vi sottopongo il mio problema: ho una registrazione utente composta da più pagine: anagrafica - ulteriori info - riepilogo. Il problema nasce quando voglio passare dalla prima alla seconda pagina premendoi il pulsante prosegui.
    La action di questa form è una funzione php che mi inserisce i dati nel db e succesivamente mi redirige alla pagina successiva mediante header('location: paginasucc.php')
    Mi restituisce, premendo "prosegui" il seguente warning:
    Cannot modify header information - headers already sent by

    so che significa che qualcosa è gia stato stampato e dovrei cercare di metterlo prima di tutto, ma va messo proprio li.. non posso spostarlo. come posso risolvere il problema?

    grazie

  2. #2
    Metti un ob_start(); all'inizio delle tue pagine (prima di ogni output).

    In questo modo "blocchi" l'output permettendo a header("Location"); di funzionare anche se si trova in mezzo o in fondo alla pagina.

  3. #3
    ob_start();

    ho letto di questa funzione, ed ho provato a metterlo proprio all'inizio della pagina, ma il risutato purtroppo non è cambiato

  4. #4
    vuol dire che non l'hai messo all'inizio (hai magari uno spazio prima del blocco PHP?) oppure un include che genera l'output o, ultima cosa da verificare, hai un ob_end_flush(); o qualcosa di simile dopo?

  5. #5
    no... non uso niente del genere. Comunque ti posto il codice che facciamo prima

    all'inizio del file registrazione.php ho :

    codice:
    <?php include("./phpUtils/login.php"); ?>
    
    <?php
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_regis")) {
       
      
      
      mysql_select_db($database_XXXconnection, $XXXconnection);
      
        	
      $insertUtentiSQL = sprintf("INSERT INTO utenti (data_modifica, nome, cognome, password, email, indirizzo, telefono, citta, provincia, data_nascita, sesso,  lat, lng) VALUES ('$now', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['txt_nome'], "text"),
                           GetSQLValueString($_POST['txt_cognome'], "text"),
                           GetSQLValueString($_POST['txt_password'], "text"),
                           GetSQLValueString($_POST['txt_email'], "text"),
    					   GetSQLValueString($_POST['txt_indirizzo'], "text"),
    					   GetSQLValueString($_POST['txt_telefono'], "text"),
    					   GetSQLValueString($_POST['txt_citta'], "text"),
    					   GetSQLValueString($_POST['txt_provincia'], "text"),
    					   GetSQLValueString($_POST['txt_data_nascita'], "text"),
    					   GetSQLValueString($_POST['list_sesso'], "text"),
    					   GetSQLValueString($_POST['hdn_latitude'], "text"),
    					   GetSQLValueString($_POST['hdn_longitude'], "text"));
      					   
      
      $Result1 = mysql_query($insertUtentiSQL, $XXXconnection) or die(mysql_error());
      $nextpage = 'moreinfo.php'; 
      header("Location: " . $nextpage );
      
    }
    
    ?>
    e questo è il file login.php che includo nel precedente

    codice:
    <?php require_once('Connections/XXXconnection.php'); ?>
    <?php
    //initialize the session
    if (!isset($_SESSION)) {
      session_start();
    }
    ?>
    <?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['txt_usrn'])) {
      $loginUsername=$_POST['txt_usrn'];
      $password=$_POST['txt_pwd'];
      $MM_fldUserAuthorization = "level";
      $MM_redirectLoginSuccess = "index.php";
      $MM_redirectLoginFailed = "errore.html";
      $MM_redirecttoReferrer = false;
      mysql_select_db($database_XXXconnection, $XXXconnection);
      	
      $LoginRS__query=sprintf("SELECT email, password, nome, level FROM utenti WHERE email=%s AND password=%s",
      GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
       
      $LoginRS = mysql_query($LoginRS__query, $sitterconnection) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
        
        $loginStrGroup  = mysql_result($LoginRS,0,'level');
    	$nomeUtente  = mysql_result($LoginRS,0,'nome');
        
        //declare two session variables and assign them
        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;	
        $_SESSION['MM_nomeUtente'] = $nomeUtente;	
    	      
    
        if (isset($_SESSION['PrevUrl']) && false) {
          $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
        }
        header("Location: " . $MM_redirectLoginSuccess );
      }
      else {
        header("Location: ". $MM_redirectLoginFailed );
      }
    }
    ?>
    grazie

  6. #6
    problema risolto: messo l'ob_start(); anche prima dell'include....

    strano però.. lo avevo fatto anche prima... mah! l'informatica è una scienza proprio strana

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.