1

i want to save output/result of JavaScript code. For example:

<script>document.write(navigator.appVersion)</script>

For PHP i have no problem:

$ip = $_SERVER['REMOTE_ADDR']; 
$file = "log.txt"; 
$open = fopen($file, "a+"); 

Then write:

fwrite($open, "<b>IP Address:</b> " .$ip . "<br/>"); 

Now i'd like to write result of JavaScript with same method.

Of course this will not work:

fwrite($open, "<script>document.write(navigator.appVersion)</script>");

Any help?

Thanks

4
  • You can't do it like that, javascript runs on the client side. You will have to first get the data and send it back to the server, or you can use the user agent Commented Mar 28, 2013 at 0:48
  • use "echo" function to write to the page Commented Mar 28, 2013 at 0:48
  • 2
    Have you tried writing the result using AJAX? You'd send navigator.appVerison to a PHP file using AJAX. Commented Mar 28, 2013 at 0:48
  • If you want to do this all server side then you'll need some sort of headless browser to render the javaScript. There are lots available for linux, a quick google just pointed me towards this: phantomjs.org Commented Mar 28, 2013 at 0:52

1 Answer 1

2

If you need to get information about the user's browser, use a PHP function. You can't get the Javascript output from PHP unless you send it back using Ajax.

To get the browser information using PHP, use get_browser()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.