Re: [PHP] References in Sessions

2010-10-14 Thread Alexander Schrijver
On Thu, Oct 14, 2010 at 05:36:29PM +0200, Sebastian Detert wrote:
> Alexander Schrijver schrieb:
> >Is my message unclear? or didn't anyone  ran into this problem?
> >
> If you want an atomic solution, you need to save the session to your
> database. How often do you need to delete data? Isn't it better to
> delete at night when noone is online, or logout all users for some
> minutes while deleting? In addition to that I don't understand, why
> it is important to prevent deletion if a point is selected ... If
> you want to work with something that was deleted, print an error and
> that's it.

Yes, i can use a database. But i can't properly use the SESSION abstraction
with a database.

suppose i build a Session handler which writes to the database it needs to
write to specific tables which contain the proper constraints.

e.g. 

table session
session_id (PK)

table companies
company_id (PK)
session_id -> session(session_id)

i.e. (one to many relationship)

Thus $_SESSION['companies'] = Array(1,2,3) needs to be translated to insert a
row in the companies table.

Now suppose someone does $_SESSION['somethingwhichdoesnexist'] = 'bladiebla'
(which is invalid) i can't make it properly fail. Because the Session handler
is run at a later point.

I can't find a method to properly work around this without rewriting to whole
session handler.

Doing deletions at night isn't solving the problem. Users can exist at night.

Printing an error isn't solving the problem either. What kind of message should
i print? "Something went wrong; i am not entirely sure what but it probably the
administrator deleted or changed a the database. Oh, and your session is now
useless".

This seemed like an obvious problem to me with an obvious solution which i
missed. Nobody has this problem?


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



Re: [PHP] References in Sessions

2010-10-14 Thread Sebastian Detert

Alexander Schrijver schrieb:

Is my message unclear? or didn't anyone  ran into this problem?

  
If you want an atomic solution, you need to save the session to your 
database. How often do you need to delete data? Isn't it better to 
delete at night when noone is online, or logout all users for some 
minutes while deleting? In addition to that I don't understand, why it 
is important to prevent deletion if a point is selected ... If you want 
to work with something that was deleted, print an error and that's it.


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



Re: [PHP] References in Sessions

2010-10-14 Thread Alexander Schrijver
Is my message unclear? or didn't anyone  ran into this problem?

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



Re: [PHP] References in Sessions

2010-10-11 Thread Alexander Schrijver
On Mon, Oct 11, 2010 at 04:43:06PM +0200, Sebastian Detert wrote:
> Why don't you write a small function checking for invalid IDs and
> delete them and referenced subIDs? If you guess it's to hard/slow to
> find out all referenced subIDs you could change your Session array
> to an multi-dimensional array, with all referenced IDs on lower
> levels
> 
> array ( sector_id => array ( company_id => array (location_id) ) );
> 
> like
> 
> array ( 1 => array (17,4 => array(2)) would mean that loction 2
> inside company 4 inside section 1 was selected. This way you only
> need to delete an old entry, and all referenced IDs dissapear
> 
> Sebastian

Hi Sebastian,

My explanation might've been unclear.

The problem isn't deleting a row and its dependencies. The problem is that i
can't delete both the reference from the database search trough all the
sessions for references (using the file mechanism). And even if i could, it
wouldn't be done atomically so it would be useless because a race could happen.

I would like to have a function which either deletes a row, or if it is
referenced by a session, fails.

And if the session would be stored in the database MySQL could take care of
this. However, the $_SESSION abstraction doesn't allow this to be implemented
properly. I think an implementation is possible, it would however be very ugly.

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



Re: [PHP] References in Sessions

2010-10-11 Thread Sebastian Detert

Alexander Schrijver schrieb:

Hi list,

I'm working on a project which uses a MySQL database to store some data. The
database looks something like this:

Companies
- id (PK)
- name
- sector_id -> Sectors (id)
- etc

Locations
- id (PK)
- company_id -> Companies (id)
- name
- etc

Sectors
- id (PK)
- name
- etc

And we're using a Session to store references (not actual PHP references
ofcourse just the identifying integers) to these tables.

For example a list of companies and locations which are selected in the GUI is
kept in the session state.

The session would look something like this when filled up. The integers are the
PKs of the companies and sectors tables respectively.

Companies = Array (1,2,3,4,etc)
Sectors = Array (1,2,3,4,etc)

The problem is: when there are 2 clients one administrative and one user,
and the user has selected a company (or something else, it doesn't really
matter). And then the administrative user comes along and deletes the row which
the user just selected from the company table. There is an invalid reference in
the Session of the user.

I figured if I saved the session in the database and used constraints (foreign
keys) to enforce this. This could work. However, the PHP session abstraction
makes it very difficult to implement this properly. (I looked at
session_set_save_handler)

How do you guys deal with this problem?

Thanks,

Alexander

  
Why don't you write a small function checking for invalid IDs and delete 
them and referenced subIDs? If you guess it's to hard/slow to find out 
all referenced subIDs you could change your Session array to an 
multi-dimensional array, with all referenced IDs on lower levels


array ( sector_id => array ( company_id => array (location_id) ) );

like

array ( 1 => array (17,4 => array(2)) would mean that loction 2 inside 
company 4 inside section 1 was selected. This way you only need to 
delete an old entry, and all referenced IDs dissapear


Sebastian

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