I want to curl a HLS that returns forbidden in the browser with Php so in another words i want to return the contents of say
http://slknjsll.azureedge.net/live/n2/playlist.m3u8
from referrer
http://60fps.xyz/chicago-bulls-philadelphia-76ers
This is for example and research purposes for the future this would be my expected results instead of a blank page
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:304
#EXT-X-TARGETDURATION:8
#EXTINF:8.342,
playlist-304.ts
#EXTINF:7.382,
playlist-305.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.342,
playlist-306.ts
#EXTINF:8.342,
playlist-307.ts
#EXTINF:8.341,
playlist-308.ts
#EXTINF:8.342,
playlist-309.ts
#EXTINF:8.342,
playlist-310.ts
#EXTINF:7.382,
playlist-311.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.342,
playlist-312.ts
#EXTINF:8.342,
playlist-313.ts
#EXTINF:8.341,
playlist-314.ts
#EXTINF:8.342,
playlist-315.ts
#EXTINF:8.342,
playlist-316.ts
#EXTINF:7.382,
playlist-317.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.342,
playlist-318.ts
Here is the code i tried but it returns blank..
<?php
function curl( $url=NULL, $options=NULL ){
/*
For SSL enabled resources
download a copy of `cacert.pem`
from https://curl.haxx.se/ca/cacert.pem
- save to your server and edit path below...
*/
$cacert='c:/wwwroot/cacert.pem';
$vbh = fopen('php://temp', 'w+');
$res=array(
'response' => NULL,
'info' => array( 'http_code' => 100 ),
'headers' => NULL,
'errors' => NULL
);
if( is_null( $url ) ) return (object)$res;
session_write_close();
/* Initialise curl request object */
$curl=curl_init();
if( parse_url( $url,PHP_URL_SCHEME )=='https' ){
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
}
/* Define standard options */
curl_setopt( $curl, CURLOPT_URL,trim( $url ) );
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );
curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh );
/* Assign runtime parameters as options */
if( isset( $options ) && is_array( $options ) ){
foreach( $options as $param => $value ) curl_setopt( $curl, $param, $value );
}
/* Execute the request and store responses */
$res=(object)array(
'response' => curl_exec( $curl ),
'info' => (object)curl_getinfo( $curl ),
'errors' => curl_error( $curl )
);
rewind( $vbh );
$res->verbose=stream_get_contents( $vbh );
fclose( $vbh );
curl_close( $curl );
return $res;
}
$m3u8url='http://slknjsll.azureedge.net/live/n2/playlist.m3u8';
$starturl='http://60fps.xyz/chicago-bulls-philadelphia-76ers';
/*
Create a store to keep any cookies found
*/
$cookiejar=tempnam( sys_get_temp_dir(), 'cookiejar_' );
/*
Specify the options for the cookies in the request
- these options are appended to those set as standard
in the `curl` function above.
*/
$options=array(
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEFILE => $cookiejar,
CURLOPT_COOKIEJAR => $cookiejar,
CURLOPT_REFERER => $starturl,
CURLOPT_HEADER => true,
CURLINFO_HEADER_OUT => true
);
/* Make the initial request to get the cookie data */
$res=curl( $starturl, $options );
/* If the request was successful, proceed - else bailout! */
if( $res->info->http_code==200 ){
/*
Make the final request but this time include the stored cookie
*/
$options=array(
CURLOPT_COOKIEFILE => $cookiejar,
CURLOPT_COOKIEJAR => $cookiejar,
CURLOPT_REFERER => $starturl
);
$res=curl( $m3u8url, $options );
/*
if the request succeeds - celebrate and do some cool stuff
with the returned data. Have a drink - you deserve it!
*/
if( $res->info->http_code==200 ){
printf('<pre>%s</pre>', print_r($res->response,true) );
}
} else {
printf('<pre><h1>Error</h1>%s</pre>', print_r($res,true) );
}
?>
Any help or advise would be great!
How we can insert header and footer in google docs with google docs api using PHP code
Writing a new and appending a file in PHP without erasing contents
How to combine 2 arrays with the condition that 2 and 5 values will be from the second array?
How to keep the ?error on url if page extension not included?
I have 4 tables : users , user_store_info , user_store_options , product_supplies
i have a datajson file like this in which i am getting a list of data i want to add another parameter{p_quantity} to this json file
I have an activity with three MenuItem'sI have three variables at the top of the activity class for each MenuItem (e
I was creating a recycler view and trying to create a toast when any item is clicked on using interface(i'm doing for first time)But my app is crashing when i click any item in recycler view