2

Here is the program listed below. I am trying to run the shell command from php so I have written the following code:

<?php    
$argument1 = $argv[1];    
$output = shell_exec('sudo whois ');    
echo "<pre>$output</pre>";    
?> 

But every time I execute the command it get executed but doesn't display output. Only shows the option.

My command in shell is php filename.php google.com

1
  • 1
    sudo-ing commands from php, with no way of bashing in the password?? Commented Dec 16, 2013 at 10:24

1 Answer 1

1

You aren't using passed argument in your command. You need to use the argument in whois command:

<?php    
$argument1 = escapeshellarg($argv[1]);  
$output = shell_exec('whois '. $argument1);    
echo "<pre>$output</pre>";    
?>

PS: whois can tun without sudo also.

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

5 Comments

don't forget to shell-escape the input :-)
Thanks @anubhava for your help and what if i want to call these from web instead from command line...
Just replace above script with: echo "<pre>" . shell_exec('whois '. $_GET['url']) . "</pre>"; and call your script as: http://domain.com/shell.php?url=google.com
Ya i just try to implement these i have two php page from one there is option for input the arguement and submit button then when i click submit button the output should redirect to the pop up php/html pages..i tried doing these please help me here
You need to make sure to use GET method in form action. Also create script as I commented above and access the direct URL as http://domain.com/shell.php?url=google.com once that is working then move on to your other script with submit button and form. If nothing works post your both PHP scripts in question so that I can debug it.

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.