I need some things clarified here:
I have a website that updates the values of two variables each time the site is reloaded in the browser. This page is obviously an HTML page but the variables are updated by javascript functions. This page runs on my server.
Can PHP retrieve the values of these variables and, using them, write them to a txt file or XML file? I realise javascript is a browser side language and PHP a server side language but I don’t know how the two can relate properly in this context.
Also I don’t have the option of recreating the javascript code as PHP script.
Is what I want to do possible?
Thanks
I am not sure when the variables are updated (if they are updated when the page is being generated, then why don’t you just do it with PHP only?). But if they are updated on the client side, based on some actions made by the user, then just do the following:
The 1st can be done using eg. jQuery’s
.post()method, and the second can be done by reading$_POSTvariable from within called PHP script (the one to which you send the data using AJAX), and by outputting it to TXT file (eg. by using PHP’sfwrite()function).EDIT: There is a great reference about AJAX. See Mozilla Developer Network article on Asynchronous JavaScript + XML (AJAX).