Skip to content

Instantly share code, notes, and snippets.

@compwright
Created November 16, 2012 23:25
Show Gist options
  • Save compwright/4091865 to your computer and use it in GitHub Desktop.
Save compwright/4091865 to your computer and use it in GitHub Desktop.
Window popup hack to establish a session inside of a Facebook app iframe in Safari
<script type="text/javascript">
// Configure these settings in your config/application.php file:
// $config['fb_page_url'] = 'https://www.facebook.com/yourfacebookpage';
// $config['fb_app_id'] = '12345667890825978';
var top_frame_url = '<?php echo config_item('fb_page_url'); ?>/app_<?php echo config_item('fb_app_id'); ?>';
<?php if (isset($_COOKIE['PHPSESSID'])): ?>
// @HACK: pop-up a window if the page is clicked (anywhere) which will access the
// host domain so we can set cookies in Safari
// http://www.digitalwks.com/blogs/diogo-raminhos/facebook-safari-session-problem-safari-iframe-set-cookie/
$(function() {
$('body').click(function() {
var win = window.open('<?php echo site_url("/start_session"); ?>', 'cookie_window', 'height=640,width=480,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0');
win.blur(); // pop under the main window
var poller = setInterval(
function()
{
if(win.closed !== false) { // !== is required for Opera
clearInterval(poller);
window.top.location = top_frame_url;
}
},
300
);
});
});
<?php endif; ?>
</script>
<?php
class Start_session extends CI_Controller
{
public function index()
{
if ( ! isset($_SESSION))
{
session_start();
}
echo <<<HTML
<script type="text/javascript">window.close();</script>
<noscript>You may close this window now.</noscript>
HTML;
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment