Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- function getContents($url,$count=0)
- {
- echo "<h2>getContents at time: ".time()."</h2>";
- $cookie="cookie.txt";
- $ch=curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt($ch, CURLOPT_HEADER, TRUE);
- if(file_exists($cookie)) curl_setopt($ch, CURLOPT_COOKIE, file_get_contents($cookie));
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $content = curl_exec( $ch );
- $info = curl_getinfo( $ch );
- curl_close ( $ch );
- echo"<h2>url</h2>".$url;
- echo"<br><h2>$cookie to send</h2>";
- readfile($cookie);
- echo"<br><h2>response</h2>";
- $content=split("\r\n",$content); // parse response headers
- echo"<table>";
- $redirect="";
- foreach($content as $c) // go thru all headers
- {
- if($k!="Content-Type") // after this header is usually site html
- {
- list($k,$v)=split(": ",$c); // parse heading data
- echo"<tr><td>$k</td><td>$v</td></tr>"; // show it
- if($k=="Set-Cookie") // if cookie, save it
- {
- $fh = fopen($cookie, 'w');
- fwrite($fh, $v);
- fclose($fh);
- }
- if($k=="Location") // if redirect, save to redirect
- {
- $redirect=$v;
- }
- }
- }
- echo"</table>";
- echo"<br><h2>info</h2>";
- var_dump($info);
- echo"<br /><br /><br /><br />";
- if($redirect!="")
- {
- if($count>2) echo "<h1>alot of redirects, halting</h1>";
- else return getContents($redirect,$count+1);
- }
- else
- {
- echo"<h1>total $count redirects</h1>";
- return $c;
- }
- }
- $c=getContents("https://marketplace.secondlife.com/p/Freebie-Tropical-Palm-Tree-with-flexi-leafs/2214529");
- echo "<h1>desired content</h1>$c";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement