2015-11-14 31 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