I have an iframe which does some server-side work and displays an image. We use the iframe in order to show image dynamically. The user hits upload image, we show a spinner, and reload the iframe with the new image. My goal is to avoid the confirm form resubmission page that displays if a user gets to the page via the ‘back’ button.
Essentially, the page which is the src of the iframe is a php file which checks against three conditions:
1) Was a variable named redirect set? If so, ‘urldecode()’ it, and use it as the img src.
2) Was a file uploaded? If so save it to the db, and redirect to this page with the image path as a GET variable
header('Location : mypage?redirect=path%2Fto%2Fimg.jpg');
die('upload');
3) Nothing was uploaded? Grab what we have from the db, then redirect to this page with the path as a GET variable
header('Location : mypage?redirect=path%2Fto%2Fimg.jpg');
die('default');
And what we have in the parent page is
<iframe id='myframe' src='mypage.php'>
Problem is, we never get a redirect. The page does die though, so instead of a profile pic, we see a white square with either the string upload or default from the die() call.
When using header() inside an iframe, does it behave as it does normally? I would like it to redirect the contents of the iframe.
Thanks for your time.
I just replicated this in my testing environment. Your header is incorrect, there shouldn’t be a space between
Locationand:Works
Doesn’t work