Running PHP code in Javascript function

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Should I be able to run something like :

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

I saw something at (a user comment at )
that made me think that I should be able to, but I can't get it to
I want to set some PHP session variables


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...

Site Timeline