Skip to content Skip to sidebar Skip to footer

Setting Php Session Var From Within Js

Is there a way to set a session variable from withing my JS function? I have the following JS code: $.ajax({ url: 'ajax.php', type: 'POST', data: { tid: '.$tes

Solution 1:

You can't set any PHP variables in JavaScript. Once the Page has finished loading PHP has done its job and is out of the picture. If you want to set a session variable using JavaScript you can do it one of two ways:

  1. Use Ajax to send the value to a PHP script to set the session variable
  2. Store it in a cookie and on the next page load have PHP use the value of that cookie to create the session varibale

Post a Comment for "Setting Php Session Var From Within Js"