Solved

PHP session variables in iframe

Posted on 2008-10-06
5
2,087 Views
Last Modified: 2013-12-13
Hi

I have a script that run smoothly without the iframe, but when i use the iframe in IE and safari it doesn't work properly.

I am searching some information from a database and display them, when I log in it create a instance of a class with all the login information encapsulate it. I save that instance variable in a session ($_SESSION['login']=&$Login) and pass it to other pages. This works great with me. But when I jump one page to the other page within iframe at the first time my php script say the session variable $_SESSION['login'] is not set, but I can go back using the browser back button and come back again, then  the php script say the session variable is set and works fine.

I know this is little bit confusing but any help is appreciate.

Thank you
~P
0
Comment
Question by:ppeiris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 6

Expert Comment

by:deresh
ID: 22653534
it seems that this is a problem with cookies that isn't set for iframe becaouse of privacy policies. try using different storage for sessions ( database, for example)
0
 
LVL 1

Author Comment

by:ppeiris
ID: 22654647
Thank you for your reply, But how can I save a class instance in to a database ? I using mysql database in the back-end but still don't understand how to store a instance in to a database. My understanding is that when I create the instance from a class template it will allocate chunk of memory for that instance and maintain all the variables in that so if I try to save that in to a database do i have to save the memory location of the instance perhaps!

Thank you
~P
0
 
LVL 2

Expert Comment

by:AdiF
ID: 22656355
Yes, it definitely sounds as though the PHP session cookies aren't being forwarded in the iframe.  Are you linking to URL's of the same domain?  (i.e. mydomain.com) and not different domains?

Anyhow; a workaround would be to append the PHP session in your link URL's. You can use the session_id() function to add an HTTP GET like myscript.php?PHPSESSID=<id here> and manually load it when you call session_start() with each script.  This method is not so secure.
0
 
LVL 1

Author Comment

by:ppeiris
ID: 22656661
Hi

Yes your correct I am using this iframe in different domain. in other words i have to display my inventory in other websites. my site is working fine even in the same script (with iframe in different domain) in firefox and safari. I have tried passing session id via weblink but still i have the same problem. I would like to try to save the session variable (in my case its a class intense) in my mysql database, but can you give me some hint how to start!

Thank you
~P
0
 
LVL 1

Accepted Solution

by:
ppeiris earned 0 total points
ID: 22663723
Hi

PROBLEM SOLVED !

I create a temporary file in /tmp dir to store my class object and reload those information when it jump to the next page.

steps:
1) create a tmp file session id as a name of the file [  $fp = fopen("/tmp/".$session_id().".txt", "w")  ]
2) serialize the class object [ $a=serialize($classobj)  ]
3) write to the file [  fwrite($fp, $a) ]
4) close the file [ fclose($fp) ]

** go to the next page **

5) get the information from the file [  $s=implode("", @file("/tmp/".$_GET['id'].".txt"))  ]
6) unserialize the class object [ $classobj=unserialize($s); ]

** now we all done... you can call a class function in the object [ $classobj->YourFunction() ]

**note: you have to delete the tmp file that you created within your script after you done with what you want.


please refer to these for more information
http://us.php.net/serialize
http://us3.php.net/unserialize


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Php logic to add to date card 9 39
Session time out quickly. 6 25
How do use '  ' within this code? 4 27
syntax error, unexpected '?' in phpunit 5 24
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question