Posted by Michael Fesser on 08/27/07 17:42
..oO(Morlaath@gmail.com)
>Anytime I embed php within javascript with the <?php ?> tags the php
>executes as soon as the page is loaded.
Sure, because that's how it works. PHP is server-side. When the page
arrives in the browser, the execution of the PHP script is finished
already.
>So for instance if I have
>something like the following.
>
>//Javascripts
>function foo() {
> <?php session_destroy(); ?>
>}
>
><input type="button" value="logout" onclick="foo();"/>
>
>The 'session_destyoy()" is called as soon as the page is loaded,
>instead of when you click on the button.
Your button click would have to invoke another server-side script to
kill the session, something like <http://example.com/logout.php>. No
need for JavaScript here.
Micha
[Back to original message]
|