javascript script result to php variable?

blargh

New member
Alright, I don't need a fancy explanation or someone to tell me I need to use AJAX... I just want the source. I don't have the time to learn JS as this project is due tomorrow afternoon.


The point of this is to have a JS code that throws a different result for everyone. I want to have the result written and logged down to an internal file, aka file.txt. I figured the best way for this is to have the entire result go into php and become equal to a variable, where then I could write the fopen/fwrite and fclose to file.txt

so now, let's pretend the main script is:
<script language="javascript">
...
...
...
...
</script>.

For everyone it is different and I want the result of the script written/logged, not the source code.

in the end I want

<?php
$jsvar = the result of the script, let in mind the script result could vary from 1 sentence, to 50 lines.

Can anyone PLEASE take the time to right this for me, as I have spent the last 24 hours straight on the computer trying to code it myself, and have failed miserably. Thank you in advance!
 
Unfortunately, you don't come here 24hrs before the due date to do your homework: it is too late!

Now, remember one essential thing:
- js code is on the user's machine.
- php is on the server.
They are MILES appart.
- php runs first, and usually generate the js code, then send it to the user. In other words, Php variables are known to Php, and can be sent to js, but NOT the other way round!!!

As you are using ajax, that is the only way to do it: send an HTTPrequest to a Php function. That request will contain the result of your js script. Your php function can then use the data received to do whatever you want, including sending an update to your user screen.
Not knowing how your AJAX is set-up, I can't really help you, but you get the basics.

js establishes the variable.
ajax takes that variable and send it to Php. (The "how" depends on your setup)
Php receives the variable and writes it to a file.
 
Back
Top