Jump to content

Using variables within an iframe


gijew

Recommended Posts

Hey all,

I'm having trouble figuring this one out so I was hoping one of you may have run into this at some point for the sake of my sanity...

Page1.html houses an IFRAME.  In the src attribute I append a few variables like siteid, color, etc...
Page2.php calls the form and stores the attributes inside of a few sessions
Form.php houses all of the forms, verification functions, etc

I can grab the iframe attributes as long as I am on host1.  If I use an absolute path on another host I am getting nothing.

I have no idea if I will be able to make this work but I'm hoping one of you might be able to (if anything) elaborate on why this is / is not possible and perhaps what to do to make it work.

I'm standing by if someone has a suggestion, I'll try anything at this point = )
Link to comment
Share on other sites

Yeah, that's what I'm thinking is going on.  Both hosts are hosted on the same server (dedicated box) so I assumed that I would be able to throw a session_start() on each page and BAM, it would work.  That's not the case.

Any suggestions on what's going on?
Link to comment
Share on other sites

It's not that straightforward, since sessions are usually identified with cookies.  And no browser will send a cookie it got from domain A to domain B.

One option is to pass the session identifier explicitly, by adding "?session=" . session_id() to the link.

Then your script on the receiving end can check for $_REQUEST['session'], and if set, call session_id($_REQUEST['session']) before session_start().

I think that ought to work, as long as both virtual hosts are storing session data in the same place.
Link to comment
Share on other sites

That's not a horrible amount of trouble but it sounds like the sessions could be flakey and I might lose the attributes and end up with some empty database fields that would get me beat down with a rubber hose.  I tried thinking of an alternate way to pass the attributes to the remote script and these are a few of the ideas I had.  But before I actually list them, I don't believe they would be any more stable.  I'll list that as well.  Hopefully someone can help me come up with some kind of idea here = )

- Store the session attributes on the page that calls the iframe into a temporary table using the ip as the PK.  LEFT JOIN on form completion and tie it together that way.  I don't think this would be very stable because you're counting on something that may be a shared resource in some companies plus you might get some empty fields in the database, not tie togther correctly, etc.

- Store the attributes into a cookie and read from that cookie.  Problem is that it's on a seperate domain so you might not be able to read from it.  I don't know, I'm just throwing that out there (in case).

That's it, not the clearest path obviously but I'm kind of drawing a blank here on the best approach.  Any help?
Link to comment
Share on other sites

Sorry for the delay in a response.  It's not like me to leave it but I've been overwhelmed with work here = /

I looked the function up in the manual and it didn't have that much in the way of help.  From what I understand is that session_write_close() will save the sessions before proceeding.  Example wise I figure it would be best to call it once you're done initiating your sessions.  It didn't work for me so I tried a few things to see exactly where this thing is dying.  I'm going to condense some code for you and maybe it's just a coding issue...

REMOTE FORM
[code]<?php
function FormInit() {
  switch ($_GET['FormAction']) {
    default: 
      return FORM();
    break;

    case 'Verify';
      return VERIFY();
    break;
  }
}

function FORM() {
  // MOSTLY HTML FORM HERE
}

function VERIFY() {
  // Verification conditionals, nothing that special.
}
?>[/code]

When I call the form remotely from another URL I do something like:
[code]<iframe src="http://www.sitename.com/page.php?Vars=whatever"></iframe>[/code]

Now I can call up the $_GET variables no problem inside of the FORM() function, remote page, etc.  When I submit the form and it posts to the VERIFY() function I lose the attributes.

Actually, writing this to you may have just led me to the problem.  I think that the URL is changing inside of the IFRAME to reflect the $_POST and I lose the $_GET variables.  I think I need a conditional here to check if they exists and if so append them to the FORM action attribute.  Whatcha think?
Link to comment
Share on other sites

I just entered pure heaven.  It's funny how when you start typing something out you notice the problem.  I still am putting the session_write_close() function in there for the sake of saving those suckas.  I do however appreciate the help from y'all. 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.