Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to use an exec shell in PHP code by connecting to a database. I had used this block of code but it doesn't work! I don't know what might be the problem, so this is my code:

if(isset($_POST['submit4']))

{
$results = shell_exec("cat /var/log/apache2/access.log | grep" . $_POST['key'] . "| sed s/'^.*apache2'/''/g | sort | uniq -c | sort -nr | cat ");
echo $results ;

}

else if(isset($_POST['submit5']))
{
mysql_connect('127.0.0.1',"root"," ") or die("erreur de connexion au serveur");
    mysql_select_db("lastnline");
        $sql='Select * from motclef';    
    $res=mysql_query($sql);
           while($row=mysql_fetch_array($res))

    {
$results = shell_exec("cat /var/log/apache2/access.log | grep" . $row['nom'] . "| sed s/'^.*apache2'/''/g | sort | uniq -c | sort -nr | cat ");
echo $results ;

    }       
}

The submit4 works very good but the submit5 doesn't work :/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
289 views
Welcome To Ask or Share your Answers For Others

1 Answer

But never populate input values directly into a shell command. Use the function escapeshellarg():

$key = escapeshellarg($_POST['key']);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...