PHP
·
发表于 5年以前
·
阅读量:8299
±¾ÎÄÖÎoÁËphpʹÓÃescapeshellargʱÖÐÎı»¹ýÂ˵Ľa¾o½¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼¡£¾ßÌaÈçÏ£º
Ò»¡¢ÎÊÌa£º
ͬÑuµÄ´uÂe£¬¢ÏÖͨ¹ý localhost/index.php ÃÎÊ£¬ºÍÔÚ shell ÖÐͨ¹ý php ./index.php ÔËÐнY¹uÈ´²»Ò»Ñu¡£
ÔÚ³ÌÐoÖÐÐeҪͨ¹ý shell_exec À´Ö´ÐÐÒ»¸o linux ³ÌÐo£¬¶øËuµÄÊaÈeÀ´×Ô echo £¬¼´£º
shell_exec('echo '.escapeshellarg($str).' | some_cmd 2>&1');
¶þ¡¢½a¾o½¨£º
¶øÕa¸o $str ÖпÉÄÜ°uº¬ÖÐÎĵġ£Ò»¿ªÊ¼ÎÒ»¹ÒÔΪÊÇ some_cmd ×Ô¼º°ÑÖÐÎÄÂ˵o£¬ºoÀ´¢ÏÖÊÇ escapeshellarg µÄÎÊÌa¡£
òËƳoÏÖÕa¸oÎÊÌaµÄ²»¶a£¬¾¹ý²eѯÓe²aÊÔ¢ÏÖÔÀ´ÊÇ shell ºÍ apache php-cgi µÄÔËÐл*¾³²»Í¬ÒýÆðµÄ¡£
ÔÚ php ÖмÓÈe£º
setlocale(LC_CTYPE, "UTF8", "en_US.UTF-8");
¾ÍÕý³£ÁË£¡
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼Òphp³ÌÐoÉe¼ÆÓÐËu°iÖu¡£