View Full Version : How to handle multiple popup windows

01-19-2010, 05:11 PM
I have a popup window that is working ok but now I want to popup a second window exactly like it. So I modified the popup window JS code and now I can do that and get the 2nd window open - however - the two windows seem to be using the same global $_SESSION vars and that I think is the problem I'm having. The windows also do an auto refresh every minute to update the display from a database.

In the window I have a drop down list where I can select a MySQL filter value and display data based on that selected filter. When I select an item from the list and click submit, my window.php script calls window_dispatcher.php and that dispatcher script assigns my list selection into a $_SESSION var ($_SESSION["filter_value"]) and then calls window.php again.

In window.php I use that $_SESSION["filter_value"] to control the MySQL filter sql statement.

So, here's the problem: with two windows open, when I set a filter in one window, when the other window refreshes, it then assumes the first windows filter setting!. I was trying to be able to open multiple windows and set different filters in each one and have them refresh independently, but I think my $_SESSION vars, being global, are ending up being 'sync'd' when each window refreshes.

So I thought well I could just eliminate the globals vars but then I don't know how to select from a drop down list and then save that value so its used when the window.php file is called again from my dispatcher script.

Maybe there is another way to do that but I've always used the main script/dispatcher script model in my php coding.

I hope I have been clear in trying to describe my problem.

01-19-2010, 05:22 PM
PHP couldn't care less how many windows you have running. As long as you have an identifier for you're session, it will use it.
The only solution is to provide something unique for each window - a get value. This can be what you're looking to use or something to help control the session flows by blocking them into multi-dimensional values instead of singular ones. It's really the only way to look at controlling two windows independant of each other but still share the same session.

01-19-2010, 05:41 PM
I found the following structure that I think need to use. The php script calling itself instead of the main/dispatcher structure I'm currently using.

But the $pullemail var is the key in this structure. If I set its value and then click submit, it's used and would send out the email, but then when the form re-displays, its value is empty again. I need to be able to save the value for reuse in the main form again after the submit.

Maybe I do have to use an array var structure of some kind.

if ($_POST['submit']) {

$pullemail = $_POST['email'];
$pullmess = $_POST['message'];

$to = "someone@example.com";
$subject = "Test mail";
$message = "$pullmess";
$from = "$pullemail";
$headers = "From: $from";
echo "Mail Sent.";
else {
<form method='post' action='test.php'>
Email: <input name='email' value="<?php echo $pullemail?>" type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />

01-19-2010, 06:59 PM
The solution was to use both _GETs and _POSTs in the single php file.

In the refresh meta tag I put this

<META http-equiv="Refresh" content="10; URL=window.php?flag=auto_refresh&emp_id=<?php echo $emp_id?>">

$emp_id holds the drop down list item selected. I selected from the list and then using an OnChange() JS event, it updates to make the database filter on that item.

Then when the meta refresh kicks in, I pass the drop down list item in a _GET so it continues to use the same value.