Calling a PHP page with get variables from Linux command line
-
28-10-2019 - |
Pergunta
I want to use wkhtmltopdf
to convert a web page to a pdf. I have test with a static template and this syntax works perfectly
wkhtmltopdf my.html my.pdf
The problem is the actual page is a dynamic PHP page with tables that rely on 3 get variables.
An example would be http://mypage.php?clientid=SJC&datestart=201201&dateend=201202 .
I can't do this directly like so:
wkhtmltopdf mypage.php?clientid=SJC&datestart=201201&dateend=201202 my.pdf
Someone suggested I needed to call the PHP from the command line with the variables first to get the HTML source code for that set of variables, then convert it using wkhtmltopdf
How do I do this? Can someone provide the process using the above URL as an example?
Solução
In linux you can use wget command to get result html from an URL:
wget "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
or
wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
to output the result to specific file ex. myfile.html
Note:
wget wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
Double quote seems to solve the ampersand encoding problem.
Outras dicas
The cleanest way would be using $_SERVER['argv']
instead of the GET variables.
However, if you HAVE to use the GET variables, you can set them in a custom script:
$_REQUEST['var1'] = $_SERVER['argv'][0];
and then require()
the PHP script itself.
Another way would be to set the environment variables QUERY_STRING
and REQUEST_METHOD
:
export REQUEST_METHOD=GET
exprt QUERY_STRING='var1=blub&var2=blah'