February 24, 2013
set php session variable using ajax/jquery
Question by user2102316
Im new to ajax/jquery. so is there an easy way that when i click a cell with in the table, the value of it will be stored in a session variable.
thanks in advance
Answer by Starx
It can be as simple as this:
The following snippet send the value to a page where session variable can be set
$.post('sessionsetter.php', { 'fieldname' : 'sessionvariablename', 'value' : 'sessionvalue'});
Now ‘sessionsetter.php’ can be something like this:
session_start();
$_SESSION[$_POST['fieldname']] = $_POST['value'];
Now, you can send as many variables you want to set as SESSION variable.