PHP code is executed on the server side and output data are transmitted to Web browser.
// JS code ... '; ?>- The string returned by 'echo' must be a JS code with correct syntax.
2) By adding in the JS script within the HTML document only the necessary data processed by PHP.
• Both versions must be written into .php files that can be processed by the PHP module.
1. Alert window with the user nameIn a web site with authentication system to be displayed an alert window with the user name, after he logged in.
In this case we assume that the username is stored in a session variable ($_SESSION['name']).
Using the first method, would be the following PHP code:
alert("Welcome '. $_SESSION['nume']. '");'; ?>
Or the second way:
- Test it yourself, in a .php file, on the server.