Sanjay Khatri Sanjay Khatri - 7 months ago 16
Javascript Question

Set Session variable using javascript in PHP

Is it possible to set PHP session variables using Javascript?

Answer

In JavaScript:

jQuery('#div_session_write').load('session_write.php?session_name=new_value');

In session_write.php file:

<?
session_start();

if (isset($_GET['session_name'])) {$_SESSION['session_name'] = $_GET['session_name'];}
?>

In HTML:

<div id='div_session_write'> </div>