I have a simple form which is inside IFRAME. When user click on SUBMIT, it redirects to a specific page on my server. The function I use for the redirect is
header ('Location: mypage2.html'); exit ();
But I want the new page to open in _top location, not inside the same IFRAME that I use. How can I tell the browser to open the new page in _top not inside the IFRAME? Thanks in advance.
Solution to the Problem To solve this problem, we have to store the header in a buffer and send the buffer at the end of the script, so to store the header in the buffer, we will use the php ob_start() function and to clean the buffer, we will use the ob_end_flush() function. See the below code snippet.
Basically, there are two types of header calls. One is header which starts with string “HTTP/” used to figure out the HTTP status code to send. Another one is the “Location” which is mandatory. replace: It is optional which indicates whether the header should add a second header or replace previous.
The header() function in PHP sends a raw HTTP header to a client or browser. Before HTML, XML, JSON, or other output is given to a browser or client, the server sends raw data as header information with the request (particularly HTTP Request).
You are not able to achieve the desired effect in PHP. This is something you'd have to do from JavaScript or add target
attribute to <form>
:
<form ... target="_top">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With