search

Home  >  Q&A  >  body text

Set session variables in PHP using javascript

Is it possible to set PHP session variables using Javascript?

P粉191323236P粉191323236231 days ago450

reply all(2)I'll reply

  • P粉276876663

    P粉2768766632024-03-28 12:10:17

    Sessions are stored server-side, so you cannot add values ​​to them from JavaScript. All you get on the client side is the session cookie containing the id. One possibility is to send an AJAX request to a server-side script, which will set session variables. jQuery’s .post() method example:

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

    Of course, you should be careful about exposing such scripts.

    reply
    0
  • P粉811329034

    P粉8113290342024-03-28 10:09:40

    In JavaScript:

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

    In the session_write.php file:

    In HTML:

    reply
    0
  • Cancelreply