Pagina 1 din 1
Trimitere date prin Post la alt site
Scris: Sâm Feb 10, 2018
de Stefan
Salut,
Cum as putea trimite date altui site? Adica eu de pe site-ul X sa trimit pe site-ul Y, unde pe Y se afla un formular.
Am gasit mai multe turoriale dar nu a functionat niciunul.
Trimitere date prin Post la alt site
Scris: Sâm Feb 10, 2018
de MarPlo
Salut
Se poate de pe server cu php cUrl.
Poti sa folosesti functia sendPostData() din urmatorul exemplu; sau vezi ce gasesti pe internet la cautare: "
php curl send post form ".
Cod: Selectaţi tot
//send $data (array [name=>value] OR string 'n1=v1&n2=v2') via Post to $url address
//Returns Response from $url
function sendPostData($url, $data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //TRUE to follow any 'Location:' header that the server sends
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to receive server response
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3); //number of seconds to wait while trying to connect
curl_setopt($ch,CURLOPT_TIMEOUT, 25); //maximum number of seconds to allow cURL functions to execute
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //FALSE to stop cURL from verifying peer's certificat
$re = curl_exec($ch); //execute and store response
if(curl_error($ch)) trigger_error('Curl Error:' . curl_error($ch)); //in case of error
curl_close($ch); //close connection
return $re;
}
//Example
$url ='https://marplo.net/page';
$post =[
'username' =>'user1',
'password' => 'passuser1',
'gender' => 1,
];
$resp = sendPostData($url, $post);
var_dump($resp);