How to Escape characters while passing system command in PHP

后端 未结 1 1139
北荒
北荒 2021-01-23 19:56

I have a Linux web server running a PHP/HTML page.

    for loop
    {
    $instruction= \"I\'m constructing the instruction here\";
    }
    $instruction = \"ls         


        
相关标签:
1条回答
  • 2021-01-23 20:41

    Make use of escapeshellcmd() in PHP

    Something like..

    $escaped_command = escapeshellcmd($command);
    exec($escaped_command);
    

    Alternatively, you could make use of escapeshellarg()

    <?php
    echo shell_exec('ls '.escapeshellarg($userdata));
    
    0 讨论(0)
提交回复
热议问题