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[$_POST['fieldname']] = $_POST['value'];

Now, you can send as many variables you want to set as SESSION variable.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!