aipsy0783 | J'aurais besoin d'aide, je pense que c'est que je recherche... une confirmation me ferait déjà plaisir lol
Je voudrais pouvoir substituer le cookie demandé par un site par des paramètres.
Code :
- <?php
- //submit login form: (url, post data, extra headers (optional))
- //do not put http into URL, just domain name
- $mycookies = GetCookies("www.yourdomain.com/login.login.asp",
- "password=12345&username=your_username&submit=LOGIN&set=Y","" );
- //some extra params if you need them
- // echo "Cookies:<br><pre>\n".$mycookies."\n</pre>";
- //$body =PostPage("www.yourdomain.com/coolpage.asp",
- //"action=zzz",$mycookies);
- //echo "<br>Body:<br>\n".$body."\n";
- //im using get page - so it goes like this:
- $opts = array('http'=>array('method'=>"GET",
- 'header'=>"Accept-language: en\r\nCookie: ".$mycookies."\r\n" ));
- $context = stream_context_create($opts);
- $fp = fopen('http://www.yourdomain.com/coolpage.asp?p1=1&p2=23', 'r', false, $context);
- fpassthru($fp);
- $html = fread($fp, 1000000);
- fclose($fp);
- echo $html;
- function PostPage($host,$query,$others=''){
- $path=explode('/',$host);
- $host=$path[0];
- unset($path[0]);
- $path='/'.(implode('/',$path));
- $post="POST $path HTTP/1.1\r\nHost: $host\r\n";
- $post.="Content-type: application/x-www-form-";
- $post.="urlencoded\r\n${others}";
- $post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
- $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
- $h=fsockopen($host,80);
- fwrite($h,$post);
- for($a=0,$r='';!$a;){
- $b=fread($h,8192);
- $r.=$b;
- $a=(($b=='')?1:0);
- }
- fclose($h);
- return $r;
- }
- function GetCookies($host,$query,$others=''){
- $path=explode('/',$host);
- $host=$path[0];
- unset($path[0]);
- $crlf = "\r\n";
- $path='/'.(implode('/',$path));
- $post="POST $path HTTP/1.1\r\nHost: $host\r\n";
- $post.="Content-type: application/x-www-form-urlencoded\r\n${others}";
- $post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
- $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
- $h=fsockopen($host,80);
- fwrite($h,$post);
- $r="";
- for($a=0;!$a;){
- $b=fread($h,512);
- echo $b;
- $r.=$b;
- $gotSession=strpos($r,"ASPSESSION" );
- if($gotSession)
- if(strpos($r, $crlf . $crlf,$gotSession)>0) break;
- $a=(($b=='')?1:0);
- }
- fclose($h);
- $arr = split("Set-Cookie:",$r);
- $AllCookies="";$count=1;
- while ($count < count($arr)) {
- $AllCookies.=substr($arr[$count].";",
- 0,strpos($arr[$count].";",";" )+1);
- $count++;}
- return $AllCookies;
- }
- ?>
|
|