Possible Duplicate:
Include PHP inside javascript (.js) file
I have been searching for a while, which I could seems to find any valid answer to my case.
I currently have a header.js file (which is my header file), inside I got a word “login” which will be linked to login.php for user to login. Now after the user have successful login to my website, how would I go and change the word “login” inside the header.js file into something else? (For example, Hello “User name” so user knows they are logged in) How do I use php in js file or even call a php file inside js? Is there a better way I can achieve this?
Thanks in advance for your time.
you could also do it via Ajax:
in the check_login.php file you can do a check to see if the user is logged in or not and return the result as a json encoded array by echoing json_encode($results);
you could also return the username of the user and append it to your linkName at that point.
Response: (“Can you show me some ample code of check_login.php file?”)
Ya, is there a specific aspect of the file you would like to have demonstrated? The logic within this file would depend on how you are setting your user login status, if you are using sessions it could look something like this: