代码:
<?php
$str = '';
$max = mb_strlen("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", '8bit') - 1;
for ($i = 0; $i < 11; ++$i) {
$str .= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[random_int(0, $max)];
}
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, "http://youtube.com/watch?v=".$str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt(/* ... */);
$content = curl_exec($ch);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
if(strpos($content, 'unavailable') !==FALSE) {
header("Refresh:0");
} else {
echo "<iframe src=\"https://youtube.com/embed/".$str."\" />";
}
} catch(Exception $e) {
trigger_error(sprintf(
'An error occured when getting video information: #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
?>
返回错误:
致命错误:获取视频信息时出错:#7: 无法连接到2a00:1450:4017:807 :: 200e:网络无法访问 在第45行的/srv/disk15/2498627/www/randomvideofinder.xyz/index.php
网站我正在尝试使用它:http://randomvideofinder.xyz/
我是个新秀。所以,如果你们中的任何人能提供帮助,那就太好了。谢谢。