トラックバック送信(POST, file_get_contents)
<html>
<head>
<title>トラックバック送信</title>
</head>
<body>
<h1>トラックバック送信</h1>
<form action="" method="POST">
<?php
if($_SERVER["REQUEST_METHOD"] === "POST") {
$tb = $_POST["tb"]; //トラックバック送信先
$tb = 'https://' . $_SERVER['HTTP_HOST'] . '/w/php/trackbackget.php'; //サンプルにつき送信先固定
$data = array( //トラックバック送信データ
'blog_name' => $_POST["blog_name"],
'title' => $_POST["title"],
'url' => $_POST["url"],
'excerpt' => $_POST["excerpt"]
);
$headers = array(
'User-Agent: Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)'
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header' => implode("\r\n", $headers)
)
);
$contents = file_get_contents($tb, false, stream_context_create($options));
echo 'トラックバック送信しました。<br><br>■レスポンス<br>';
echo '<textarea rows="20" cols="80">', $contents, '</textarea>';
}
else {
echo '
■トラックバック送信先<br>
<input type="text" name="tb" size="100"><br>
<br>
■blog_name<br>
<input type="text" name="blog_name" size="100"><br>
<br>
■title<br>
<input type="text" name="title" size="100"><br>
<br>
■url<br>
<input type="text" name="url" size="100" value="http://"><br>
<br>
■excerpt<br>
<textarea rows="20" cols="80" name="excerpt"></textarea><br>
<br>
<input type="submit" name="submit" value=" 送信 ">
';
}
?>
</form>
</body>
</html>
〔 実行する 〕