Retrieve curl data with client headers/IP
我有同样的问题。我不明白,但不是在localhost。我本地主机上的一切都很好。只是在我的网站上没有得到正确的视频网址。我猜有一些服务器ip问题。
$url_in = 'http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1';
function curl($url, $cookie = false, $post = false, $header = false, $follow_location = false)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_location);
if ($cookie) {
curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
}
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec ($ch);
curl_close($ch);
return $response;
}
$vk_video = curl($url_in);
preg_match('|host=(.*)&|Uis', $vk_video, $link1);
preg_match('|uid=(.*)&|Uis', $vk_video, $link2);
preg_match('|vtag=(.*)&|Uis', $vk_video, $link3);
$link= $link1['1'].'u'.$link2['1'].'/video/'.$link3['1'].'.360.mp4';
echo $link;
答案 0 :(得分:2)
<?php
function geturl($url, $quality)
{
$vkurl = file_get_contents($url);
preg_match('/&url'.$quality.'=(.*?)&/mis', $vkurl, $C);
return $C[1];
}
echo geturl('http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1', '240'); //gives 240p video
echo geturl('http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1', '360'); //gives 360p video
echo geturl('http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1', '480'); //gives 480p video
echo geturl('http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1', '720'); //gives 720p video
注意:您无法为客户生成视频网址。您只能为您的服务器生成URL,然后您可以从您的服务器中播放视频