tags:

views:

38

answers:

2

I am creating application in facebook using iframe. In that i want to redirect from one page to another. i m using following code:

<fb:redirect url='http://....' />

but this is not working and instead of redirecting it stays on same page. so i used following code:

header("Location: http://.......");

this is working properly but problem is that it doesn't open in full window it opens in main window i.e address of first page in address bar and in that page in square it opens second page that is redirected to. can we give target="_top" attribute in header function of PHP Please help me....

A: 

You need to add die();

header("Location: http://.......");
die();

Your current page will not stop rendering when you change any header. It will just set the header - as long as there is nothing already renderd! Please be sure that you don't have any html output before setting this header redirection!

And this code will only be executed if the IFrame is reloaded / you click a link or do a form submit to the same page.

Andreas Rehm
I tried what you said but still it's not working and giving same display as before.
+1  A: 

You can't give a target to the header() function (it's running on the server - it doesn't know it's being called by a frame).

You could add the following javascript to the second page to "break out of the frame".

<script type="text/javascript">
    <!--
        if (top.location!= self.location) {
            top.location = self.location.href
        }
    //-->
</script>

If you don't want to rely on javascript, you'll need a link on the second page to itself, but with target="_top"

Paul Spangle