T
T
timofy2017-07-05 17:48:57
PHP
timofy, 2017-07-05 17:48:57

Why doesn't php compile to javascript code?

The question is:
you need to get the IP of site visitors. JavaScript doesn't seem to have this option. But there is such an opportunity in PHP, IP users are recorded here:
$_SERVER['REMOTE_ADDR']
I use NodeJS as a server.
In the index.html file, I inserted the script:

<script type="text/javascript">
        var ip = "<?php echo $_SERVER['REMOTE_ADDR'] ?>";
        alert("Твой IP "+ip);
        alert(ip);
</script>

PHP installed
But in the browser PHP is not compiled:
37efb6e9109c44fea9ac26d637d0e639.png
Why? What could be the reason?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
E
Edward, 2017-07-05
@timofy

NodeJS

var ip = req.headers['x-forwarded-for'] || 
     req.connection.remoteAddress || 
     req.socket.remoteAddress ||
     req.connection.socket.remoteAddress;

A
Alexey Sklyarov, 2017-07-05
@0example

because you are trying to insert php code into the html document

I
Igor, 2017-07-05
@DMGarikk

Well, because NodeJS is not PHP.

T
ThunderCat, 2017-07-05
@ThunderCat

I use NodeJS as a server.
In the index.html file, I inserted the script:

1) The node responds to all requests via http, so there is no one to give the file for interpretation in PHP
2) Is PHP installed on the server at all?
3) php is not compiled, but interpreted.
4) standard extension for processed php files (surprise!) - .php

S
Semyon Beloglazov, 2017-07-05
@Batlab

Because php interpreter is not working for you. Most likely, localhost is listening to node.js, not php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question