Domanda

I tried to assign a var with gethostname() (1) and with $_SERVER(2) and I keep on getting ReferenceError: gethostname is not defined.

All I want is to get the current system name into a var using JS which runs in my PHP. What am I doing wrong?

UPDATE:

var myVar = gethostname();

or

var myVar = $_SERVER; 
È stato utile?

Soluzione 2

So, I approached this whole issue a little differently, and my initially approach was wrong to begin with.

I decided to get the IP address by executing

$ipAddress = getenv("REMOTE_ADDR");

Then I wanted to get the host name, so I did a shell execution:

$myArg = "nslookup $ipAddress";

Eventually I used stripos to get the start ("name = ") and end ("domain.name") positions of the host name, and eventually I used substr to get the hostname out.

I will use the result to pass it to the JS.

Altri suggerimenti

thats clear it says that there is no code like "function gethostname()" that means it cant work if you try to get the hostname via the var you try to get

<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;
?>

this would get the hostname of the server where the script is running on!

since $_SERVER['REMOTE_ADDR'] is the own servers ip address

<?php 
//Gets the IP address
$ip = getenv("REMOTE_ADDR") ; 
Echo "Your IP is " . $ip; 
?> 

will get the ip of the user that runs the script since getenv("REMOTE_ADDR") contains the ip of the user

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top