-2

I am new to php, I am currently facing problem using header function.

Currently I am working on a ticketing system, in which when all of the user credentials are validated he is redirected to the payment gateway. On successful payment completion I have to redirect him back to the the page where validation was done. I am using header function to do this. My concern is how is the call stack when header function is called, I am not able to visualize the call stack do i need to manage it or php does it on its own.

Any help will be appreciated.

  • 1
    Put your redirection logic at the top of your script. – meda Apr 04 '14 at 19:35
  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – bjb568 Apr 04 '14 at 20:31
  • My question was how to manage the call stack and I was not concerned about header ob_start was something I didn't knew. – user2963604 Apr 05 '14 at 20:34

1 Answers1

3

There is nothing special about how header is called. It's a function just like any other.

However, due to the way output is sent to the browser, it is essential that any header calls be made before any output is sent. Any at all. Not even a single space is allowed. Personally, I achieve this effect with ob_start(), however be aware that doing so prevents longer pages from being downloaded in pieces - they must be processed to completion before they are sent. In my case, that's not a problem, because my pages generate in less than a tenth of a second.

Keep in mind, however, that just because you use header to start a redirect, that does not stop the rest of the script from being executed. You will almost always want to exit; immediately after the header call.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592