开发者

Call PHP document with SSH includes get variable

开发者 https://www.devze.com 2023-04-05 18:25 出处:网络
I have the following in a PHP document I\'m calling from a cron job. if (is_file($docRoot . $row[\'cron_a开发者_高级运维ction_script_path\'])) {

I have the following in a PHP document I'm calling from a cron job.

if (is_file($docRoot . $row['cron_a开发者_高级运维ction_script_path'])) {

    system("php " . $docRoot . $row['cron_action_script_path'] . $row['params']);
}

However, I'm getting the error Could not open input file: /path/to/file.php?params=1

But I am getting past the if statement is_file('/path/to/file.php')

So it looks like there's a problem with including get variables on SHH calls to PHP document.

Is there anyway around this? I need to be able to dynamically call my params in some fashion.


if (is_file($docRoot . $row['cron_action_script_path'])) {
    $_GET['params'] = $row['params'];
    include $docRoot . $row['cron_action_script_path'];
}


You are making a call to the php CLI and attempting to use QUERY STRING data, which is webserver specific. You will either need to revamp the script to accept parameters or call it using a program such as lynx, curl or wget

So make the system call something like:

system("wget http://yourdomain.com/path/to/file.php?params=1 > /dev/null");

Which should then execute that script using webserver which would allow the QUERY STRING.

EDIT:

Tailored to using your variables: (Note there may need to be a slash after the .com)

system("wget http://yourdomain.com" . $row['cron_action_script_path'] . $row['params'] . " > /dev/null");


Try is_readable instead of is_file. A file can exist without being readable by your current user.

Passing params like that isn't going to work, though. You can't do $_GET variables on the commandline. Take a look at how PHP expects and handles commandline arguments.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号