Call PHP document with SSH includes get variable
Asked Answered
C

3

0

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

if (is_file($docRoot . $row['cron_action_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.

Caralie answered 19/9, 2011 at 18:10 Comment(2)
Post the command for your cron job.Lubricity
I know the job works correctly. I confirmed by running without params (ie system('php path/to/file.php')) and got the correct response.Caralie
C
4
if (is_file($docRoot . $row['cron_action_script_path'])) {
    $_GET['params'] = $row['params'];
    include $docRoot . $row['cron_action_script_path'];
}
Cuttlebone answered 19/9, 2011 at 18:15 Comment(3)
According to OP's code, it appears that $row['params'] contains ?params=1 (other rows may contain even more fields) so he'll have more work to do.Seibert
I think this could work, but $row['params'] is a string that could be anywhere from ?id=1 to ?id=1&foo=2&bar=3 so I would have to reparse the $_GET['params']? parse_str maybe?Caralie
@stevether: Yes, parse_str would be the way to go.Seibert
Z
3

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");
Zincography answered 19/9, 2011 at 18:12 Comment(4)
Could you elaborate on "revamp the script"? I also tried doing the system calls with the programs you listed (in order): Alert!: Unable to access document. lynx: Can't access startfile, curl: (3) <url> malformed, Unsupported scheme.Caralie
For the revamp, you just need to rewrite to accept argurments, see ceejayoz's post for the link on how this is handled. As for your lynx etc, it seems you have a bad url, if you can post the code you ran it with I can help you fix the error.Zincography
This looks promising but I have an .htaccess blocking access to the directory of the file. There's no way to do it internally?Caralie
Take a look at Col. Shrapnel's post. His way can be done internally, just may require a bit of tailoring to it.Zincography
A
1

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.

Adamite answered 19/9, 2011 at 18:11 Comment(2)
I tried that an it passed. The problem isn't necessarily checking if it's a file, but passing parameters to said file.Caralie
I was addressing that in an edit as you typed that comment. See above.Adamite

© 2022 - 2024 — McMap. All rights reserved.