views:

43

answers:

2

Hi,

I use a content management system called liferay that lets you add iframes to a page very easily. I have various different iframes that i want to use the same php session variables. This wouldn't be an issue if the main webpage was setting the sessions. the problem is the sessions are created in one iframe and I'm wanting to use them in another?

Normally the session id could be passed via the url but that's not how I have it set up. There is no navigation like that. the iframes display content from a database based on the session variables set up in the first iframe, but they are not linked.

Can someone help me out here? I'm not sure how else iframes can share session variables.

Thanks,

Jonesy

A: 

If the domain remains the same, the first iframe will create the session and the second iframe will just pick it up after session_start()

You dont really need to pass the session in the URL for this or anything. The first iframe while writing the session data will lock the session data. However there is a problem, with iframes you can never be sure that the first iframe does load first, maybe cause of network congestion or something it is possible that the second iframe loads first. So maybe to counter this delay loading the second iframe a bit.

Sabeen Malik
thanks for your reply. when i try to set the session variable via the iframe i can't access them in any of the other iframe pages (loaded afterwards). but when I open the iframe setting the variables in a new window, i can then access these variables from evry iframe. It's like the fact that it's in an iframe is makin if keep the variables private, but opening it in a new window makes them public. hope that makes sense. and i'm making sure i use session_start();
iamjonesy
why not set the session_id in the mainpage and set subsets in the iframes
Grumpy
@Jonesy .. can you post some code from the PHP files you are calling from the first and second iframe?
Sabeen Malik
A: 

As Sabeen said, if you are using cookie based session tracking (which is what PHP uses by default, if the user agent supports cookie) the session will be picked up automatically. You might run into trouble if the pages loaded in the Iframe are from different subdomains. In that case, you have to use the session.cookie_domain configuration variable.

ini_set("session.cookie_domain", ".domain.com");

Joyce Babu
@Joyce thanks, they are just local just now. liferay runs at localhost:8080 and the php files localhost/clientportal
iamjonesy
try `echo session_id();` in the iframe pages to ensure that the session ids are same in both.
Joyce Babu
thanks for that tip. the session id for the iframe web that sets the sessions is different than any other iframe page. why do you think that is?
iamjonesy
After a quick google search, i think the problem is related to your hostname (localhost). Is it possible for you to use an alias, say example.com, by editing your host file?
Joyce Babu
These are my suggestions. 1) Try with a virtual host or alias. 2) If 1 doesn't work, try setting `session.cookie_domain` to 127.0.0.1. 3) If 2 doesn't work, then install LiveHTTPHeaders Firefox addon to find out why your session cookie is not getting saved.
Joyce Babu