Solved

PHP session variables in iframe

Posted on 2008-10-06
5
2,089 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP $_POST vs asp request 4 55
history of pages 7 48
Change background images after 5 seconds. 12 44
How do I correctly structure this insert statement 3 26
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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