Set Session variable using javascript in PHP

后端 未结 9 955
刺人心
刺人心 2020-11-27 21:23

Is it possible to set PHP session variables using Javascript?

9条回答
  •  -上瘾入骨i
    2020-11-27 22:10

    The session is stored server-side so you cannot add values to it from JavaScript. All that you get client-side is the session cookie which contains an id. One possibility would be to send an AJAX request to a server-side script which would set the session variable. Example with jQuery's .post() method:

    $.post('/setsessionvariable.php', { name: 'value' });
    

    You should, of course, be cautious about exposing such script.

提交回复
热议问题