473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sessions and iframes

Hi,

I have a very basic idea of PHP session management. From what I know, in order to maintain variables across multiple scripts in an app. we can store them in a session.

I have a main page - index.php in which I have an iframe referencing another php script - bar.php. All I am trying to do is access the session variables from the index page in the iframe, which, so far I haven't been able to accomplish.

My code is as follows:

index.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4. $_SESSION['myVar']="hello" ;
  5.  
  6. $sessId=session_id();
  7. echo "<br> sessId: " . $sessId . "<br>" ;
  8.  
  9. print('<iframe name="test" id="test" src="foo/bar.php?sessId='.$sessId.'" marginwidth=0 marginheight=0 onload="this.height=this.contentDocument.height" width="100%" frameborder="0" scrolling="yes"></iframe>');
  10.  
  11. ?>

bar.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $sessId = $_REQUEST['sessId'] ;
  4.  
  5. if(session_id() == "") 
  6. {     
  7.     session_id($sessId);
  8.     session_start(); 
  9.     echo "<br> sessId: " . $sessId . "<br>" ;//shows the same session-id as index.php
  10.     echo "<pre>" ;
  11.     print_r($_SESSION); //shows an empty array
  12. else
  13. {
  14.     //something
  15. }
  16.  
  17. ?>
Earlier I noticed that simply saying session_start() in the iframe-script was actually creating a new session with a different session id, hence I appended the session id from index.php into the iframe URL so that I can try to access the same ongoing session from bar.php, but print_r($_SESSION) doesnot show me anything.


Where might I be going wrong? Any suggestions?
Feb 22 '09 #1
2 10518
I just tested the code your posted and it is working fine for me. I just do not get a session when I visit bar.php because there is no open session on that page not allowing access of session information... I would suggest changing your bar.php to this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start(); 
  4. echo "<br> sessId: " . session_id() . "<br>" ;//shows the same session-id as index.php
  5. echo "<pre>" ;
  6. print_r($_SESSION); //shows an empty array
  7.  
  8. ?>
  9.  
That should give you the results you need.
Feb 22 '09 #2
Hi again,

Just to be clear, what I am basically trying to do is customize an existing application to add some functionality, hence the goof ups, I apologize.

More information:

I have xampp on my localhost; scampering around the app I realized that the session files were stored in a dir data/sessions/ which had an htaccess file in it, could that have something to do with me not being able to access the session variables from within the iframe?

Another thing which I noticed was that the iframe did print the session vars set in other test scripts that I wrote... just not the ones from the parent page in which it was embedded.

I am not very adept at PHP or Apache for that matter, but it looks to me like some security measures are implemented by the original app creators so as to avoid the session vars being accessed by any other code outside that application (such as my iframe), can this be tackled?

Any help appreciated!
Feb 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: maxim vexler | last post by:
I'm reading a lot of talks lately about the term iFrame and with your permission would like to ask a few question about that : - what is iFrame, i mean what is it good for ? - does all the...
0
by: Dan Popa | last post by:
Check out the following 2 links: http://www.batisdev.com/admin/test_1images.asp http://www.batisdev.com/admin/test_2images.asp First page contain 4 IFRAMES and 1 IMG tags. Second page contain 4...
5
by: Frances | last post by:
I need to replace iframes acc. to what option user chooses in a sel obj.. but figured have to load a blank iframe when pg loads so I can replace it.. (iframe gets put in a pre-existing div..) this...
2
by: David | last post by:
Hello, When the user starts my .aspx page and then opens a new browser window (i.e. through menu or Ctrl + N hotkey) I don't want both pages to share the same Session (HttpApplication.Session)....
8
by: Ashish | last post by:
Incase the problem got bogged down reposting... Hi Gregory, I think I didnt make myself much clear. The problem is: 1. I have one ASP.NET application (no classic asp) and it has a main page...
7
by: Ron Vecchi | last post by:
I've been searching to find an answer but can not. I have a site that started out using the defaul session cookieless="false" Most pages have an IFrame located on them. I decided to change to...
2
by: Guadala Harry | last post by:
1. Are IFrames supported only in uplevel versions of IE? If not IE exclusively, what browsers support IFrames? 2. Are IFrames going to be supported in the future - as far as anyone knows - or...
3
by: Giggle Girl | last post by:
Is there a way to use Javascript to detect if a browser supports IFrames, or (if it DOES support them) that IFrame use is enabled? Thanks, Ann
19
by: wmanzo | last post by:
I have a really professional conspiracy movie site and I use tons of layers and an external scroll bar assembly. I would like to put the various sections into MS Iframes and in order to clean up...
2
by: ericisjusteric | last post by:
I have a page with multiple iframes and need to have the user (ie6) be able to click a button to refresh any one of the iframes - but also to click another button at the top of the page to refresh...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.