0

I have a PHP webpage that takes which accepts a rather large POST array. I have a button on the page that opens a PHP popup window. Is there a convenient way to pass the entire $_POST array to the popup?

Edit: It is an entirely different page. I open it with JavaScript: window.open

Brian
  • 26,662
  • 52
  • 135
  • 170
  • More details regarding the popup would help. Does your popup require a separate page load or is it from an AJAX request? – Corey Ballou Jan 05 '10 at 23:37

4 Answers4

0

The most convenient way would be to use session variables. If your POST data is really big you might hit some performance issues though, so beware.

Post receiving page:

session_start();
//...
$_SESSION['post_for_popup'] = $_POST;

Popup:

session_start();
//...
do_something($_SESSION['post_for_popup']);
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
0

try

var_export($_POST,1);
streetparade
  • 32,000
  • 37
  • 101
  • 123
0

Well, you could use a $_SESSION variable. I assume the popup is a completely separate page so there is no other viable way to transfer the variables without doing a postback. So you could do something like this:

index.php:

session_start();
$_SESSION['post'] = $_POST;

popup.php:

session_start();
$_POST = $_SESSION['post'];

Hope that helps.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185
  • Why would you overwrite $_POST? – Vinko Vrsalovic Jan 05 '10 at 23:38
  • Because that would be most intuitive to use, for me at least, and given that there is no other $_POST data, I can't see why not. This way you can use the data in it's original context - it is/was POST data after all. – Tatu Ulmanen Jan 05 '10 at 23:40
  • 1
    Overwriting post would be a good idea if you already had the script in place. That way you wouldn't have to retrofit the whole mess. – Joe Mills Jan 05 '10 at 23:41
  • I think overwriting a global variable with precisely defined meaning is disaster waiting to happen. Having the script already written is no excuse, search and replace is really easy these days. – Vinko Vrsalovic Jan 05 '10 at 23:55
  • @Vinko, sure it can be dangerous, but doing a $_POST -> session -> $_POST doesn't smell disastrous to me, as in this case nothing will come inbetween. – Tatu Ulmanen Jan 06 '10 at 00:15
  • Just make sure you HTML encode the data before or as you print it out in the popup. – TravisO Jan 06 '10 at 00:56
  • @Tatu: I'm thinking about the future. In the short term there will probably be no problems. But it is a time bomb that might explode some months or years in the future when you forget and try to POST to the popup or a new developer works on that code. And for no good reason, use another variable and there's no risk at all, it may be just a bit less convenient. – Vinko Vrsalovic Jan 06 '10 at 01:35
0

You could do one of two things.

First you could assign it to a session variable and load that session variable from the popup.

Or you could do a quick script to iterate through the $_POST array and add them as request vars on the url. This may not be right for you as your $_POST is big.

You could do the second option and add it into the header as post vars using the header() command, but I'm not sure what the added value would be there.

If I was to do it I'd put it into the session. Even a HUGE post var isn't going to take up that much session memory.

Joe Mills
  • 1,619
  • 11
  • 12