php - make curl get the final url and use it for another function -
i have url variables example : http:// remotesite.com/index1.php?option=com_lsh&view=lsh&event_id=149274&tid=372536&channel=0
this url redirect http://remotesite.com/static/popups/xxxxxxxxxxx.html
xxxxxxxxxxx variables 1st link, event_id=149274, tid=372536, channel=0
then xxxxxxxxxxx = 1492743725360 , link :
http://remotesite.com/static/popups/1492743725360.html
how link automatically in php link http:// remotesite.com/index1.php?option=com_lsh&view=lsh&event_id=149274&tid=372536&channel=0
then use curl function source code of 1492743725360.html
using :
<?php //get url $url = "http:// remotesite.com/static/popups/1492743725360.html"; //get html of url function get_data($url) { $ch = curl_init(); $timeout = 5; //$useragent = "mozilla/5.0 (windows; u; windows nt 5.1; en-us)applewebkit/525.13 (khtml, gecko) chrome/0.x.y.z safari/525.13."; $useragent = "ie 7 – mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; .net clr 1.1.4322; .net clr 2.0.50727; .net clr 3.0.04506.30)"; curl_setopt($ch, curlopt_useragent, $useragent); curl_setopt($ch, curlopt_failonerror, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch,curlopt_url,$url); curl_setopt($ch,curlopt_returntransfer,1); curl_setopt($ch,curlopt_connecttimeout,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $html = file_get_contents($url); echo $html; ?>
$url = 'http://remotesite.com/index1.php?option=com_lsh&view=lsh&event_id=149274&tid=372536&channel=0'; $parsed = parse_url( $url ); parse_str( $parsed['query'], $data ); echo $newurl = 'http://remotesite.com/static/popups/'. $data['event_id'].$data['tid'].$data['channel']. '.html';
outputs:
http://remotesite.com/static/popups/1492743725360.html
Comments
Post a Comment