php - Using CURL to get remote page source code and create new HTML file with variable name -


after doing 3 hours of research , reading decided post question share reached , asking help,

here trying have created .php file executing 3 operations:

1-curl function source code of remote page.

2-creating new html file containing code got remote page.

3-open file in current window

i tried make basic @ first applying on google.com remote page , local host.

the file test.php present in localhost/test.php , code is:

<?php     //get url     $url = "http://google.com";      //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);     $fp = @fopen('google.html', 'w') or die('could not open file, or fike not exist , failed create.');     $mytext = $html;     @fwrite($fp, $mytext) or die('could not write file.');     ?>     <script type="text/javascript">     window.location.href = 'google.html'; //will take google.     </script> 

and works perfect :d have proceeded apply on actual site remote page link got dynamically code below:

<html> <script type="text/javascript"> function getqueryvariable(variable,def) {   var query = window.location.search.substring(1);   var vars = query.split("&");   (var i=0;i<vars.length;i++) {     var pair = vars[i].split("=");     if (pair[0] == variable) {       return pair[1];     }   }   return def; } function redirect(){     window.location.href = 'static/popups/'+getqueryvariable('event_id',0)+getqueryvariable('tv_id',0)+getqueryvariable('tid',0)+getqueryvariable('channel',0)+'.html'; }  </script> <body onload="redirect()"> <style>body{background-color: #000000; text-align: center;}</style> </body></html>  

so resulting link http://remotepage.com/static/popups/xxxxxxxxxxxxx.html xxxxxxxxxxxxx numbers got code above

how can code of xxxxxxxxxxxxx.html , create html file named xxxxxxxxxxxxx.html @ mysite.com/static/popups/

<script type="text/javascript"> function getqueryvariable(variable,def) {   var query = window.location.search.substring(1);  //returns query string of url.   eg, after "?" in url.   var vars = query.split("&");                      //this , next couple lines find right key in url   (var i=0;i<vars.length;i++) {     var pair = vars[i].split("=");     if (pair[0] == variable) {       return pair[1];     }   }   return def; } function redirect(){     window.location.href = 'static/popups/'+getqueryvariable('event_id',0)+getqueryvariable('tv_id',0)+getqueryvariable('tid',0)+getqueryvariable('channel',0)+'.html'; }  </script> 

so, quick , easy way grab query string of url using parse_url.
then, parse using parse_str.
after that, fill in bits , pieces url suppose go to.

parse_str returns named array. so, if query string ?event_id=2&tv_id=100, can event_id going $arr['event_id'] after parse string.
then, replace each call function matching variable.
getqueryvariable('event_id',0) replaced $arr['event_id'].

if parameter not defined, 0 instead.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -