How can I make a request with both GET and POST parameters in PHP with cURL? How can I make a request with both GET and POST parameters in PHP with cURL? curl curl

How can I make a request with both GET and POST parameters in PHP with cURL?


# GET query goes in the URL you're hitting$ch = curl_init('http://example.com/script.php?query=parameter');# POST fields go here.curl_setopt($ch, CURLOPT_POSTFIELDS, array('post' => 'parameter', 'values' => 'go here'));

PHP itself wouldn't decide to ignore the GET parameters if a POST is performed. It'll populate $_GET regardless of what kind of http verb was used to load the page - if there's query parameters in the URL, they'll go into $_GET.

If you're not getting $_POST and $_GET with this, then something is causing a redirect or otherwise killing something. e.g. have you check $_SERVER['REQUEST_METHOD'] to see if your code is actually running as a POST? PHP won't populate $_POST if a post wasn't actually performed. You may have sent a post to the server, but that doesn't mean your code will actually be executed under a POST regime - e.g. a mod_rewrite redirect.

Since you have FOLLOW_REDIRECT turned on, you're simply ASSUMING you're actually getting a post when your code executes.


i don't know maybe you already have but is your $url has the desired get parameters? Like:

$url = "http://example.com/index.php?param1=value1&param2=value2";