PHP通过命令行传递的参数被截断
我使用PHP的PHP通过命令行传递的参数被截断,php,phantomjs,Php,Phantomjs,我使用PHP的shell_exec()通过命令行执行程序,并将URL作为参数传递给它 问题:程序似乎只接收到参数的截断版本。PHP传递参数 http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1 但该计划将其视为 http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?c
shell_exec()
通过命令行执行程序,并将URL作为参数传递给它
问题:程序似乎只接收到参数的截断版本。PHP传递参数
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1
但该计划将其视为
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616
如何防止它在和之后被截断
PHP
$url = 'http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1';
$script = path('base')."application/phantomjs/httpget.js";
$output = shell_exec("phantomjs $script $url");
httpget.js
// Get URL from command line parameter
var system = require('system');
var url = system.args[1];
console.log(url);
输出
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616
引用您的字符串:
$url = 'http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1';
$script = path('base')."application/phantomjs/httpget.js";
$output = shell_exec("phantomjs $script \"$url\"");
例如,考虑以下内容:
~ $ echo foo&bar
[1] 25361
foo
-bash: bar: command not found
[1]+ Done echo foo
~ $
vs
引用您的字符串:
$url = 'http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1';
$script = path('base')."application/phantomjs/httpget.js";
$output = shell_exec("phantomjs $script \"$url\"");
例如,考虑以下内容:
~ $ echo foo&bar
[1] 25361
foo
-bash: bar: command not found
[1]+ Done echo foo
~ $
vs
使用
使用
这段代码看起来很容易注入。如果某人有URLhttp://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1&foo=;rm-rf.
?我看不出问题所在……您还有什么没有告诉我们的吗?顺便说一句。。。arxanas=very wise personI在由phantomjs
调用的httpget.js
中做了一个console.log(url)
,它给了我参数的截断版本@谢谢你!我没注意到。所有的URL都是由我定义的,所以我想这应该没问题,我尝试了xdazz的答案,它工作得很好:)这段代码看起来很容易注入。如果某人有URLhttp://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1&foo=;rm-rf.
?我看不出问题所在……您还有什么没有告诉我们的吗?顺便说一句。。。arxanas=very wise personI在由phantomjs
调用的httpget.js
中做了一个console.log(url)
,它给了我参数的截断版本@谢谢你!我没注意到。所有URL都是由我定义的,因此,我猜这应该没问题,我尝试了xdazz的答案,效果很好:)引用是一种方式,但请不要手动-如果$url
可以包含不可信的数据,这将打开一个巨大的安全漏洞。噢,法律,现在有更好的答案时,答案就是引用是一种方式,但请不要手动-这将打开一个巨大的安全漏洞如果$url
可能包含不受信任的数据。噢,现在如果有更好的答案,这就是答案