post in php

To post data in PHP, you can use either GET or POST method. The GET method sends the data as a part of the URL, while the POST method sends the data separately in the HTTP request.

To post data using the POST method, you can create a form with input fields for each data you want to post. Then you need to set the method attribute of the form to "POST". Upon submitting the form, the data will be posted to the specified URL.

Alternatively, you can also use the cURL library in PHP to POST data. With cURL, you can set the data as an array or a string, and specify the URL to which the data should be posted. Here's an example:

main.php
// Create a new cURL resource
$curl = curl_init();

// Set the URL and POST data
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://example.com/post.php",
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        "name" => "John",
        "age" => 30,
        "color" => "blue"
    )
));

// Execute the request and get the response
$response = curl_exec($curl);

// Close cURL resource
curl_close($curl);

// Do something with response
echo $response;
471 chars
23 lines

In this example, we're setting the URL to "https://example.com/post.php" and posting three data values: "name", "age", and "color". You can modify this code according to your needs.

gistlibby LogSnag