我想做的是编写一个代码,通过它可以将嵌入方法发送到表单方法post的不和谐服务器中。但是事情是我每次打开链接示例后都发送了一个embed。 mywebsite.com/discord,即使输入为空,它也会再次发送它,只是直接发送上一条消息($ post_news)。代码可能看起来完全错误,但是我无法尽力使用php做很多事情。这是代码;
<?php
if(isset($_POST['password'])){
$post_pass = $_POST['password'];
if($post_pass == "9896"){
$post_title = $_POST['title'];
$post_news = $_POST['update'];
$post_date = date("c");
$rand = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
$post_color = '#'.$rand[rand(0,15)].$rand[rand(0,15)];
// Replace the URL with your own webhook url
$url = " r";
$hookObject = json_encode([
/*
* The username shown in the message
*/
"username" => "test",/*
* Whether or not to read the message in Text-to-speech
*/
"tts" => false,/*
* File contents to send to upload a file
*/
// "file" => "",/*
* An array of Embeds
*/
"embeds" => [
/*
* Our first embed
*/
[
"author" => [
"name" => "test",],// Set the title for your embed
"title" => "$post_title",// The type of your embed,will ALWAYS be "rich"
"type" => "rich",// A description for your embed
"description" => "
$post_news
","timestamp" => "$post_date",// The integer color to be used on the left side of the embed
"color" => hexdec( "$post_color" ),// Footer object
"footer" => [
"text" => "TEST",]
]
],JSON_UnesCAPED_SLASHES | JSON_UnesCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch,[
CURLOPT_URL => $url,CURLOPT_POST => true,CURLOPT_POSTFIELDS => $hookObject,CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
]
]);
$response = curl_exec( $ch );
curl_close( $ch );
die("send");
}
else{
die("wrong password");
}
}
?>
<!DOCTYPE html>
<html>
<body>
<center>
<br><br><br>
<form method="POST">
<label>PASSWORD</label>
<input name="password" required ><br><br>
<label>POST TITLE</label>
<input name="title" required ><br><br>
<label>POST INFO</label>
<textarea name="update" required="" style="margin: 0px; width: 537px; height: 179px;"></textarea><br>
<button>ИЗПРАТИ</button>
</form>
</center>
</body>
</html>