jagguy
jagguy

Reputation: 183

cant redirect outside an iframe with cakephp3

I have an application where I need to redirect to a website ( example below). My issue is that the cakephp3 application is embedded in a wordpress iframe and for some reason the below command executes inside an iframe so i have a webpage within a webpage. How can i redirect to a webpage outside an iframe?

//controller
if ....
    return  $this->redirect('http://www.xxxxxx/thank-you-application/');

Upvotes: 0

Views: 332

Answers (1)

Benfarhat
Benfarhat

Reputation: 183

  • What goes on in Vegas, stays in Vegas
  • What goes on in an iframe, stays in that iframe

I don't think what you want is possible with PHP (and any PHP framework), Maybe with getting the content of the page that you want to load inside the iframe with:

$http = new Client();
$response = $http->get('http://example.com');
$content = $response->body();

and put the $content in the view in the "top level page / mean not inside iframe" (like they do in financial website), but i'm not sure of the exact way.

the easiest solution is to send in your controller a value ($redirect = true) to the view that will say: "Hey! view, plz open this link to the top level window! / mean outside the iframe".

write something like this in your view (or template):

<!-- ... -->
 <?php if($redirect) : ?> 
 <body onload="javascript:window.top.location.href='<?= $this->Url->build([
    "controller" => "Pages",
    "action" => "display",
    "thank-you"
     ]) ?>'";>
<?php else: ?>
<body>
<?php endif; ?>
<!-- ... -->

Hope it helps

Upvotes: 0

Related Questions