Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
Where is the best place to put header("Location: loggedin.php");

I am writing an inventory Management system. I am mostly complete with it. It is pretty basic, but does the job.

So now I am working on the look of it. I placed a Searchbox/Query inside a div at the top of the page. The Search works. But it only displays the result on the page that is listed.

What I want to do is have the Search redirect to this page when the button is Submitted, but It is not working. So I am wondering where to put the header("Location: loggedin.php");

I have gotten this to work in different parts of the Site, but for some reason it is not working here.

<?php

session_start();

if( isset( $_POST['Search'] ) ) {

// build a function to validate data
function validateFormData( $formData ) {
    $formData = trim( stripslashes( htmlspecialchars( $formData ) ) );
    return $formData;
}

$formEmail = validateFormData( $_POST['email'] );

include('connection.php');



$query = "SELECT first_name, last_name, email, card_number, pc_type 
FROM 
profiles WHERE email ='$formEmail'";
$result = mysqli_query( $conn, $query );


if( $formEmail == $email )  {


        session_start();


        $_SESSION['email'] = $email;

        header("Location: profilepage2.php");

    }
}
 mysqli_close($conn);

?>

I do not think the HTML should matter in this case, but if I am wrong I will post it in an edit.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can put your header("Location: your-url") anywhere in your script but it should be placed before you send any output as defined in the manual here http://php.net/manual/en/function.header.php.

You need to add exit; immediately after the header which is very important, Otherwise the script execution will not be terminated.

you must use like,

header(“Location: loggedin.php”);
exit;

If redirect is not working then try to add ob_start at the first line of your script just next to the open PHP tag like below,

<?php ob_start();
over 4 years ago · Santiago Trujillo Relatório

0

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda