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.
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.