tags:

views:

77

answers:

4

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

A: 

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
You have to take care that the session is populated before the popup makes its request.
Ignacio Vazquez-Abrams
A: 

try

var_export($_POST,1);
streetparade
And how do you send it to the popup?
Vinko Vrsalovic
A: 

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
Why would you overwrite $_POST?
Vinko Vrsalovic
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
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
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
@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
Just make sure you HTML encode the data before or as you print it out in the popup.
TravisO
@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
A: 

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