POST data and redirect user by PHP CURL POST data and redirect user by PHP CURL curl curl

POST data and redirect user by PHP CURL


As I found, it is not possible just with PHP.

You can generate a form with PHP and submit that with JS in onLoad.

Here is more detail.


This is my workable solution for post with curl:

$postdata = "email=".$username."&pass=".$password; $ch = curl_init();curl_setopt($ch, CURLOPT_VERBOSE, false);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch,CURLOPT_POST, sizeof($postdata));curl_setopt($ch,CURLOPT_POSTFIELDS, $postdata);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  $result = curl_exec ($ch);curl_close ($ch);

There is an alternative solution if above doesnt works:

$ch = curl_init();curl_setopt($ch, CURLOPT_VERBOSE, false);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  $result = curl_exec ($ch);curl_close ($ch);