I am using Ubuntu and xampp, I am trying to execute the command nslookup gmail.com
via. PHP, but I am getting an empty response. The same thing worked while I tried on a windows machine as well as in a Linux server running CentOS.
FYI nslookup gmail
gives proper response when I run the command directly on my terminal, the problem is only when I try to do it via. php.
I even tried doing a which nslookup
and then
$nslookup = shell_exec("/usr/bin/nslookup $server");
with no help, but the same blank response.
Although Note that the command whoami
when executed from PHP(which I have commented in the following code) does give a proper response of daemon
I am very new to Ubuntu, so a little help would be great.
<?php
$email = $_GET['email'];
$server = explode("@", $email)[1];
echo $server;
$nslookup = shell_exec("nslookup $server");
// $nslookup = shell_exec("whoami");
print_r($nslookup);
?>
The php script executes as less privileged www user (daemon in your case) when you execute via web browser. It doesn't have enough privilege to execute command
nslookup
. I won't recommend increasing privilege of www user, which is a security risk. As an alternative try gethostbyname php function. It returns IPv4 address corresponding to a given Internet host name.