Include PHP $_SESSION var on INSERT, UPDATE & DELETE
Include PHP $_SESSION var on INSERT, UPDATE & DELETE
I'm using Editor, and trying to find a way to make database actions include a PHP $_SESSION variable for the currently logged in user. I am using the PHP libraries provided with Editor. This is a multi-user web app where users manage their own records, so and I really need queries to look something like this...
[code]
INSERT INTO table (name, age, user_id) VALUES ($name, $age, $_SESSION['user_id'])
[/code]
Without hacking the PHP libraries, what are my options?
Note: "user_id" is a field I'm NOT exposing in DataTables.
[code]
INSERT INTO table (name, age, user_id) VALUES ($name, $age, $_SESSION['user_id'])
[/code]
Without hacking the PHP libraries, what are my options?
Note: "user_id" is a field I'm NOT exposing in DataTables.
This discussion has been closed.
Replies
[code]
$data = $_POST;
$data['session_id'] = $_SESSION['id'];
Editor::inst( $db, 'browsers' )
->fields(
...
)
->process( $data )
->json();
[/code]
i.e. just modify the data that Editor is sending to the PHP classes before the data is processed. You'd also need to include a field for the session_id of course - to the Editor class it will look like Editor has submitted the value. But we know differently ;-).
Allan
[quote]
PHP Fatal error: Cannot use [] for reading in ...
[/quote]
> $data = $_POST[];
It should have been:
[code]
$data = $_POST;
[/code]
I've edited the above post incase anyone else also wants to use this method.
Allan
[code]
private function _insert( )
{
$set = array();
$set['user_id'] = $_SESSION['user_id']; //Modify insert to include user_id
[/code]
As far as I can tell this shouldn't break anything.