Redirecting in PHP

Asked

Viewed 127 times

0

Next, I created a page to edit a piece of content and I would like it to go back to the previous page when I click the refresh button. I’m using the following command:

header("Location: visualizarNovaPrevisao.php");

However, a warning appears:

Warning: Cannot Modify header information - headers already sent by (output Started at C: Program Files (x86) Vertrigoserv www marco php editaNovaPrevisao.php:276) in

I’ve read about that warning, but I don’t understand what they say about output on line 276. Does anyone know how to use redirect?

  • This is typical of when there is some space after the closure of tag ?>

  • What do you mean? When a space is left after closing the php tag? But there is no way to have space! Unless you mean space of the following form ? >, this?

  • Take a look at item 3 of Otto’s answer. That’s what I’ve been meaning to say. It’s even advisable to not even put the tag PHP closure, just to avoid this problem.

  • 1

    From a look at the wiki of the php tag there are two answers about this error.

  • On wikipedia, @lost?

  • No, when you click on the language tag it opens the questions and a tab called info there generally has various information like list of resources, common problems etc. tag link The content about the error is at the end of the page.

  • Sorry @lost, I don’t understand yet.

  • @Gustavosevero which part you didn’t understand?

  • 1

    Gustavo, every tag on this site has a wiki: http://answall.com/tags/php/info

Show 4 more comments

4 answers

0

1) Find the header() , the statement that is causing the problem. The error must be equal to the above.

2) Search for all statements that could send the output to the user before this header declaration. If you find one or more, find some way to move the header statement before them. Complex conditional statements can complicate the problem, but they can also help solve the problem. Consider a conditional expression at the beginning of the PHP script that determines the header value as early as possible, and fix it there.

3) Make sure there is no white space outside the beginning and end of php tags. While a blank line before the

4) An important detail, editors with UTF-8 support like DWCS4 and Eclipse save the file. php with Unicode Signature (BOM), just uncheck this option, save and solved problem.

  • I have this at the beginning of my php: include"connection.php"; session_start(); $id = $_SESSION['id']; $user = $_SESSION['user']; $cc = $_GET['cc']; $id = $_GET['id']; $nAnalise = $_GET['na']; $qryBusca = "SELECT * FROM [RDO]. [dbo]. [ANALISE_CRITICA] WHERE NMANALISE='$nAnalise' AND ID='$id' "; $stmtQry = sqlsrv_query( $Conn, $qryBusca ); ? > After that is an html to show the content I will edit.

  • saw all 4 steps ?

  • 4th I didn’t get it right. Put as meta tag in html?

  • We cannot try to improve the reading .... some editors may save the file with utf-8 encoding with good being necessary to save with utf-8 encoding only understood

0

You forgot about href -

function voltar () { 

    window.location.href="http://www.google.com   ou  seu caminho da pagina" ;
}

and the button

<input type="button" onclick="voltar()">
  • 1

    Well, I did it in an old way that I learned when I learned php. When I click update, I have another php do the update and at the end I put the header where I wanted and ready!

  • 2

    That answer was really for that question?!

  • @bfavaretto really this answer has nothing to do with redirecting php kkk has every crazy

0

The error is happening because it is not possible to send the header after the contents of the file.

Somewhere before the header() exists or an html tag, a echo or even a blank space outside the <?php ?>.

It shows the error in the file editaNovaPrevisao.phpin line 276, because it is there that was written a content for the file.

If it is not possible to remove or modify the place of data output you will have to redirect via Javascript.

In this other question you find a more detailed explanation of what might cause this error:

Error - "Cannot Modify header information - headers already sent"

-1

If you have been using Dreamweaver, it should be saving some extra characters at the beginning of your code. Do the following: Open your php file and go to Save As and uncheck: Include Unicode Signature (GOOD). If it still persists, open the script in Notepad++ and remove the existing characters at the beginning of the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.