2

I have a structure of a page which has iframe of a different domain inside a page. both the domains are owned by me only. The problem I am facing is I cannot access session of a parent frame inside an iframe. I have also tried with database session but I am not getting a session variables inside an iframe.

<body>
<?php Yii::app()->session['myvar']="iframeVar";?>
<iframe scr="https://xyz.com.au"></iframe>
</body>

and xyz.com.au looks like

<body>
<?php echo Yii::app()->session['myvar'];?>
</body>

Please guide me.

Thanks.

Dirgh
  • 507
  • 4
  • 13
  • are you using a separate yii installation on your second domain (the domain which is opened in your iframe)? – deacs Feb 17 '14 at 12:55
  • Yes... a separeate istallation on a separete server with different domain – Dirgh Feb 18 '14 at 01:14
  • One thing to note with iframes is that IE and Safari will not allow you to send cookies if your website is inside an iframe, so you will need session ID in query string. – Igor Jerosimić Sep 04 '15 at 14:47

1 Answers1

0

The following comes from this question:

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

You could try using the following code on the page of the seperate Yii installation:

$session=new CHttpSession;
$session->open();

The open() method calls the php method session_start() which should resume the session you had in your parent frame. Try accessing your variable like so:

echo $session['myvar'];

Hope that helps. If not, try checking this question too.

Community
  • 1
  • 1
deacs
  • 4,259
  • 2
  • 27
  • 37
  • Thanks for answer but I already tried this but its not working .. Answer I could find for this said the same origin policy for security does not allow cross session access... I am looking to have alternative yii specific way. – Dirgh Feb 19 '14 at 00:10
  • What do you get when you `echo Yii::app()->session->sessionID` in both frames? – deacs Feb 19 '14 at 00:59