0

I have two pages. First one we open with $_POST variables in its url, the second one opens inside first via iframe. Both php files, second is for html manipulation.

Variables I got in $_POST are passed to iframe via $_GET:

echo '<iframe src="index.php&first=' . $first . '&second=' . $second . '&third=' . $third . '&iframe=true"></iframe>';

$first, $second, $third variables has text inside them with some html and new lines (\n).

The problem is, when data is passed to iframe by $_GET, all the new lines in variables disappear.

Tryed to pass variables like base64_encode($first), and then decode them by base64_decode(). It works buggy, some parts of text don't decode correctly, maybe because of bad symbols in iframe url.

Also tryed to throw all the variables into single array, serialize it and then encode by base64 - this way server gives error 500 (it also gives the same error for 404).

Please don't ask me why I did such structure of pages. It should not be changed.

What is the solution for this?

hakre
  • 193,403
  • 52
  • 435
  • 836
Jasper
  • 5,090
  • 11
  • 34
  • 41
  • Be careful doing this. query strings have a length limit and will silently truncate anything that's too long, and this could happen client-side AND/OR server-side without warning. – Marc B Mar 25 '12 at 17:28

4 Answers4

3

What about an urlencode after the base64_encode?

haltabush
  • 4,508
  • 2
  • 24
  • 41
  • @Steve doing it together makes very little sense. – Your Common Sense Mar 25 '12 at 17:05
  • @Your Common Sense your sarcastic comment doesn't make sense. First, iframe is used for live preview, so your answer is not the solution at all. Second, my code is clear, don't say it is bad before you see. Third, be patient. – Jasper Mar 25 '12 at 17:18
  • @Steve I see it already. you are going to urlencode base64_encoded data. And you don't care. That enough. – Your Common Sense Mar 25 '12 at 17:20
  • @YourCommonSense : I'm a PHP developer who cares. You're absolutely right about base64_encode, it's pretty useless here. But still, if you have any explanation about what happened on his problem, I could use it. From what I know, base64_encode should be enough? – haltabush Mar 25 '12 at 17:30
0

Depending on your situation you could also use Javascript to access the parent frame.

You could store the data in a javascript array of the first window, then the iframe sub window could call it via parent.*

Some more details from other questions.

Community
  • 1
  • 1
Dustin Graham
  • 2,054
  • 1
  • 20
  • 24
  • there is no way to access iframe's content – Jasper Mar 25 '12 at 17:12
  • its impossible due to browser security politics – Jasper Mar 25 '12 at 17:13
  • Steve, I'm not suggesting accessing the child frame's content. I'm suggesting accessing the parent frame's content from the child. Try creating a parent frame with `` and from the child try `` and you'll see it is an [object Object] not undefined. So, instead of passing the variables to the child via $_GET, just store the variables in `` then in the child iFrame try `parent.myVars.whatever;` – Dustin Graham Mar 26 '12 at 18:34
-1

You could write the contents of $first,$second,$third to first.txt,second.txt,third.txt and then open the text files inside your iframe script

Zed
  • 595
  • 5
  • 4
-1

Your initial approach is wrong.

POST variable shouldn't go anywhere. After the POST request server have to order browser to reload the page. Whole page, not only iframe in it.

After that reload you may show any iframes to user.
To pass the data there, a session would be ideal solution.
However, certain solution depends on the data nature and overall purpose of all the mess.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345