Running PHP code in Javascript function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Japhy

    #1

    Running PHP code in Javascript function

    Hello,
    Should I be able to run something like :

    function setvars()
    {
    <?php $_SESSION['VARa'] = 'ABC' ; ?>
    }

    I saw something at php.net (a user comment at
    http://us2.php.net/function.session-start)
    that made me think that I should be able to, but I can't get it to
    work.
    I want to set some PHP session variables

    THANKS

  • mcauser

    #2
    Re: Running PHP code in Javascript function

    Your could possibly use some form of AJAX inside your javascript
    function to post the data to another php page that sets the variables.

    You wont be able to access the session variables on the above page that
    contains the javascript though because the php code on the page has
    already been executed prior to the javascript being interpreted. You
    will need to either refresh the page or navigate to another.

    If you are going to do that, you might as well just include at the top
    of the subsequent page the save session vars script...

    Comment

    Working...