How to insert javascript value into the php session variable
I want to insert javascript value into the php session variable but inside the javascript function. Here is what I have tried and it is not working: function languageChange() { var lang = $('#websites1 option:selected').val(); <?php $_SESSION['SESS_LANGUAGE']?> = lang; alert(<?php echo $_SESSION['SESS_LANGUAGE']?>); } You cannot access it directly (the way you are doing). However, it can be done using AJAX. Here is the perfectly working solution. Here is the HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html