Passing $ _GET or $ _POST data to a PHP script that is run using wget

I have the following line of PHP code that works fine:

exec ('wget http://www.mydomain.com/u1.php > / dev / null &');

u1.php acts to perform various types of maintenance on my server, and the above command does this in the background. No problems.

But I need to pass the variable data to u1.php before it executes. I would prefer to transmit POST data, but could contribute GET or SESSION data if POST is not an option. In principle, the type of data transferred depends on the user and may vary depending on who is registered on the site and runs the above code. I tried adding the GET data to the end of the url and it did not work.

So, how else can I send data to u1.php? Preferred POST data, SESSION data will also work (but I tried this and it did not collect user session data in the log). GET will be the last resort.

Thank!

+3
source share
3 answers

, , , http_build_query

exec("wget --post-data 'a=b&c=d' http://www.mydomain.com/u1.php > /dev/null &");

, wget over cURL , , . wget .

+2

cURL ( )? POST.

curl -d "your=postdata&more=postdata" http://www.mydomain.com/u1.php
+1

Why not use the cURL implementation directly?

$c = curl_init('http://www.mydomain.com/u1.php');
curl_setopt($c, CURL_POSTFIELDS, $post_data);
curl_exec($c);

EDIT: To send $post_data, you create a line such as a GET request line:

$vData = array(
  'foo' => 'bar',
  'zoid' => 'frob',
  'slursh' => 'yargh',
);

$post_data = array();

foreach ($vData as $k => $v)
   {
       $post_data[] = urlencode($k) . '=' . urlencode($v);
   }

$post_data = implode('&', $post_data);
0
source

Source: https://habr.com/ru/post/1782013/


All Articles