2015-11-14 33 views
1

我想用PHP来获得这个网站的内容,最终目的我想M3U8链接 它需要登录 http://tv24.vn/livetv/vtv1.html 这是信息测试: 用户: [email protected] 通过:12345678 我试图使用卷曲POST但不成功!PHP - 如何获得与登录信息内容

<?php 
$username = '[email protected]'; 
$password = '12345678'; 
$loginUrl = 'http://tv24.vn/livetv/'; 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $loginUrl); 

curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password); 

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

$store = curl_exec($ch); 

$return=file_get_contents("http://tv24.vn/livetv/vtv1.html"); preg_match('/file: "(.*?)"/', $return, $m3u8); 
echo $m3u8; 
?> 

任何解决方案? 非常感谢!

回答

0

像这样的事情应该去做

$username = 'h2132704%40trbvm.com'; 
$password = '12345678'; 
$url = 'http://tv24.vn/account/login'; 


//login form action url 
$postinfo = "email=".$username."&password=".$password; 

$cookie_file_path = "cookie.txt"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_NOBODY, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
//set the cookie the site has for certain features, this is optional 
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0"); 
curl_setopt($ch, CURLOPT_USERAGENT, 
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); 
curl_exec($ch); 

//page with the content I want to grab 
curl_setopt($ch, CURLOPT_URL, "http://tv24.vn/livetv/vtv1.html"); 
//do stuff with the info with DomDocument() etc 
$html = curl_exec($ch); 
preg_match('/file: "(.*?)"/', $html, $m3u8); 

print_r($m3u8[1]); 

curl_close($ch); 
+0

感谢ü非常感谢! – Fr0zEn

+0

如果它是正确的,请接受它。 – Jah