Do you want to post data one website to another website using PHP ? It’s actually pretty easy to do. Here’s the code.
<?php

“Arisha”,
“last_name” => “Ahsan”,
“email” => “bdparul@gmail”,
);

$ch = curl_init ($url_to_post);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data_to_post);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$return_data = curl_exec ($ch);
curl_close($ch);
?>

And what happened? Here’s my quick explanation.

$url_to_post

The url where you want to post your data to

$data_to_post

The post data as an associative array. The keys are the post variables

$ch = curl_init ($url_to_post);

Initializes cURL
Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions.

curl_setopt ($ch, CURLOPT_POST, true);

Tells cURL that we want to send post data

curl_setopt ($ch, CURLOPT_POSTFIELDS, $data_to_post);

Tells cURL what are post data is

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

Tells cURL to return the output of the post

$returndata = curl_exec ($ch);

Executes the cURL and saves theoutput in $return_data
Execute the given cURL session.
This function should be called after initializing a cURL session and all the options for the session are set.

curl_close($ch);
Closes a cURL session and frees all resources. The cURL handle, ch, is also deleted.
Helpfull Link
That’s it. I believe it’s assist you.

Advertisements