CodeIgniter Forums
Redirect with target="_top" option - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Redirect with target="_top" option (/showthread.php?tid=68102)



Redirect with target="_top" option - Wouter60 - 05-25-2017

I have a web page that is embedded in an iframe on another website. The page has a form with the buttons Cancel and Continue.
On Cancel, I want to address a controller function which destroys the session, after that, the user should be redirected to the top level of the website with the iframe.
Until now, I have this code linked to the Cancel button:
Code:
<a href="....." target="_top">Cancel</a>
But I want to destroy the session before that. Any ideas?
A simple redirect without the target="_top" option will load the whole website inside the iframe.


RE: Redirect with target=&quot;_top&quot; option - InsiteFX - 05-25-2017

Create a function/method in a CI helper to destroy the session

PHP Code:
$CI =& getinstance();
$this->CI->session->sess_destroy(); 



RE: Redirect with target=&quot;_top&quot; option - Wouter60 - 05-25-2017

I've found a solution:

PHP Code:
public function cancelled()
{
 
 $this->session->sess_destroy();
 
 echo "<script>top.window.location = 'http://the-top-website'</script>";
 
 die();