Re: [PHP] requests from 2nd window breaks my program

2006-08-14 Thread afan

 on rereading your post - your storing session data in a db, why bother;
 secondly
 it sounds like you just overwriting the session record with a new
 transaction
 id rather than adding a new transaction id [record] and leaving any
 already existing
 transactions available.

 basically pass the transaction id around when you need to keep referring
 to
 an existing transactions and maintain a 'stack' of active transactions.



Reason I store session info in 'sessions' table

CREATE TABLE `sessions` (
  `sessID` varchar(45) NOT NULL default '',
  `last_update` timestamp(14) NOT NULL,
  `session_values` text NOT NULL,
  PRIMARY KEY  (`sessID`)
) TYPE=MyISAM;

instead in $_SESSIONS (something like $_SESSION['session_info']['User'],
$_SESSION['session_info']['UserNo'], $_SESSION['session_info']['OrderID,
'], $_SESSION['session_info']['PageID'], etc.) is to be able to see who is
online, eventually by redoing sessions table, when they started session,
how much time they spend on application, what they mostly use from
application, etc. (requests from the office).

-afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] requests from 2nd window breaks my program

2006-08-11 Thread afan
I'll try to explain my problem as better as I can. Please, be gentle :)

I developed a program for our salespeople (only them, no public) where
they can order items for their customers. Order form is made of 6 pages
(order info, items info, artwork, ad copies,...). Also, they use the same
program to manipulate saved/submitted orders, send confirmation to
customers, requests to suppliers,... Code works fine. But this morning I
found a bug that if Salesperson open 2nd window in this program, since it
has the same session id, it would make a mess with session. I.e., on 1st
window I'm doing an order. Order ID, customer ID, transaction ID are
stored in session table. In the middle of the order I open 2nd window to
check a price on an other customer order. After I opened that order new
order ID and customer ID are stored now in session table and the order
(1st window) is now broken or goes to wrong place.
Or, I'm sending request for approval of an order to customer. But, second
before I submit the request, I open an order of other customer. Other
customer ID is now stored in session table and conf. email goes to wrong
place.
There are few more scenarios of bug make mess.

Did anybody had a problem with 2nd window and how is it solved? What's
wrong with structure/idea I used to make a program?
Any comment will be helpful to determine or give me an idea how to fix
this bug.

Thanks for any help.

-afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requests from 2nd window breaks my program

2006-08-11 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 I'll try to explain my problem as better as I can. Please, be gentle :)
 
 I developed a program for our salespeople (only them, no public) where
 they can order items for their customers. Order form is made of 6 pages
 (order info, items info, artwork, ad copies,...). Also, they use the same
 program to manipulate saved/submitted orders, send confirmation to
 customers, requests to suppliers,... Code works fine. But this morning I
 found a bug that if Salesperson open 2nd window in this program, since it
 has the same session id, it would make a mess with session. I.e., on 1st
 window I'm doing an order. Order ID, customer ID, transaction ID are
 stored in session table. In the middle of the order I open 2nd window to
 check a price on an other customer order. After I opened that order new
 order ID and customer ID are stored now in session table and the order
 (1st window) is now broken or goes to wrong place.
 Or, I'm sending request for approval of an order to customer. But, second
 before I submit the request, I open an order of other customer. Other
 customer ID is now stored in session table and conf. email goes to wrong
 place.
 There are few more scenarios of bug make mess.
 
 Did anybody had a problem with 2nd window and how is it solved? What's
 wrong with structure/idea I used to make a program?

the problem is not '2nd Window' but rather that you are using the session id
to uniquely indentify an order [manipulation] process/transaction (which 
consists
of multiple http requests) ...

a very crude idea below (you have to add a request variable named 'ordertransid'
in all links pointing to pages that have to act on an existing order 
transaction,
leaving it out would generate a new order transaction (on the relevant page[s])
for which you can then use the newly appointed transaction id to point 
subsequent
pages to the transaction that was just created:

function getOrderTransactionData()
{
if (!$_SESSION['ordertransstack']) {
$_SESSION['ordertransstack'] = array();
}

$transid = @$_REQUEST['ordertransid'];
if (!$transid || !isset($_SESSION['ordertransstack'][$transid])) {
$transid = count($_SESSION['ordertransstack']);
$_SESSION['ordertransstack'][$transid] = 
initNewOrderTransactionData();
} else {
$data = $_SESSION['ordertransstack'][$transid]; 
}

return array('ordertransid' = $transid, 'data' = 
$_SESSION['ordertransstack'][$transid]);
}

function setOrderTransactionData($data)
{
if (!$_SESSION['ordertransstack']) {
$_SESSION['ordertransstack'] = array();
}

$transid = @$_REQUEST['ordertransid'];
if ($transid  isset($_SESSION['ordertransstack'][$transid])) {
$_SESSION['ordertransstack'][$transid] = $data;
return true;
}

return false;
}

function deleteOrderTransaction()
{
$transid = @$_REQUEST['ordertransid'];
if ($transid  isset($_SESSION['ordertransstack'][$transid])) {
unset($_SESSION['ordertransstack'][$transid]);
return true;
}

return false;
}


list($orderTransId, $orderTransData) = getOrderTransactionData();

on rereading your post - your storing session data in a db, why bother; secondly
it sounds like you just overwriting the session record with a new transaction
id rather than adding a new transaction id [record] and leaving any already 
existing
transactions available.

basically pass the transaction id around when you need to keep referring to
an existing transactions and maintain a 'stack' of active transactions.


 Any comment will be helpful to determine or give me an idea how to fix
 this bug.
 
 Thanks for any help.
 
 -afan
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requests from 2nd window breaks my program

2006-08-11 Thread Andrew Kreps

Based on the general description you've given, I could imagine adding
a 'step number' in your session.  Then validate it against what step
is being loaded.  So, if you set your Session 'step' variable to 5,
and page 6 is loaded, that would seem OK.  If your Session 'step'
variable is 6, and page 2 is loaded, that could throw an error.

I should note that I think my solution is treating the symptom rather
than the disease.  I don't know enough about your application to tell
you what the right solution should be, but I think there must be a
more graceful way to handle this.

On 8/11/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

I'll try to explain my problem as better as I can. Please, be gentle :)

Did anybody had a problem with 2nd window and how is it solved? What's
wrong with structure/idea I used to make a program?
Any comment will be helpful to determine or give me an idea how to fix
this bug.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requests from 2nd window breaks my program

2006-08-11 Thread Andrew Kreps

For what it's worth, I like Jochem's solution much better than the one
I gave you.  :)

On 8/11/06, Jochem Maas [EMAIL PROTECTED] wrote:

a very crude idea below (you have to add a request variable named 'ordertransid'
in all links pointing to pages that have to act on an existing order 
transaction,
leaving it out would generate a new order transaction (on the relevant page[s])
for which you can then use the newly appointed transaction id to point 
subsequent
pages to the transaction that was just created:


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php