Help with cUrl

Hi guys! I have recieved a cUrl script that I want to incorporate in my homepage. It will register people for a site. I have only recieved the cUrl code without proper guidance. First I only pasted the code in a php file but then I realized that I need some kind of input form. So checked a bit of youtube. Here is what I got so far:

The form

<fieldset>
<legend>Form</legend>
<form action="test.php" method="post">
<label>Full Name: </label><input type="text" name="fullname" /><br />
<label>Email: </label><input type="text" name="email" /><br />
<input type="submit" name="submit" value="submit" />
</form>
</fieldset>

And script

<?php

$apiUrl = "https://udimi.com/api/affgen/addref";
$headers = [
    "Content-Type: application/json",
    "Auth: Generated auth code here"
];
$referral = [
    'fullname' => 'Referral Fullname',
    'email' => '[email protected]'
];

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $apiUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($referral),
    CURLOPT_HTTPHEADER => $headers
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

I was quite happy because it ended up in the homepage as a “pending user” basically. But, the name and email was the same as in the code above, Referral fullname and [email protected]

So I think I am getting close. Any pointers here?

Getting close to what? What is the problem?

The site that the form is registering the user to is not picking up my name and email that I input in the form.

If I enter Patrik as name and my email it still spits out the name “Referral fullname” and the email [email protected] that is in the code. So it doesn’t take my input from the form

You have to use the data from your form

var_dump($_POST);

https://www.php.net/manual/en/reserved.variables.post.php

Sorry, total noob here. So, do I just add that in the php and all good? I don’t want to experiment to much with actually sending the data because there is a limit to the amount of “pending users” I can have

Sponsor our Newsletter | Privacy Policy | Terms of Service