Skip to content

Instantly share code, notes, and snippets.

@mdsdias
Created July 22, 2022 20:06
Show Gist options
  • Save mdsdias/d802161688ada240b16edc412d4b6ae3 to your computer and use it in GitHub Desktop.
Save mdsdias/d802161688ada240b16edc412d4b6ae3 to your computer and use it in GitHub Desktop.
a webhook with php curl
function postToDiscord($username, $message, $url)
{
$payload = json_encode(array(
'username' => $username,
//'avatar_url' => $this->avatar,
'content' => $message,
//'embeds' => $embeds,
//'tts' => $tts,
));
$dc = curl_init();
curl_setopt($dc, CURLOPT_URL, $url);
curl_setopt($dc, CURLOPT_POST, TRUE);
curl_setopt($dc, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($dc, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($dc, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($dc, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($dc, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($dc);
curl_close($dc);
return $json_result = json_decode($result, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment