Jump to content

Recommended Posts

Hey,

Approximately 2 years ago i asked a question on regular expressions, the topic is therefore archaeic and unrecoverable but contained the info i needed to solve my current problem.

 

<?php
$mycookies = GetCookies("www.site.com/login.php",
"usrname=user&password=pass&usermail=user@email.com&submit=LOGIN&set=Y","");
$opts = @array('http'=>array('method'=>"GET",
'header'=>"Accept-language: en\r\nCookie: ".$mycookies."\r\n" ));
$context = stream_context_create($opts);
$fp = fopen('http://www.site.com/statistics.php?id=2111292', 'r', false, $context);
fpassthru($fp);
$html = fread($fp, 1000000);
fclose($fp);
$strip = strip_tags($html);
echo $strip;

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;

}
?>

 

This is my current script - if i just run down what im doing here. I'm using fsock to establish a connection to a third party site and then submitting a set of details in order to login - i then strip the html tags away from the page that i've fopened and read.

 

What i now need is to use preg_match to extract the string "Rank: 999,999" for example and then split that down to 999,999 and then remove the comma - this is the part i am stuck on - i just really don't understand regular expressions.

 

Does anyone think they could help me out here and then explain it?

 

Thank You  ;D

Hi OLG. Neat scrape.

 

I'm not so good with RegEx either, but you can probably get what you want with explode() alone.

// after you've assign $html
$x= explode('Rank: ',$html,2);
if($x[1]) $y = explode(' ',$x[1],2);
$rank = str_replace(',','',$y[0]);

if(is_numeric($rank)) echo $rank;
else echo 'this didnt work after all..';

I don't think that worked

 

Additionally - i have now fixed the stripping issue (stupidly used fpassthru - now sorted) - however there is still some javascript in the result - so i need to remove that.

 

I'm fairly certain that it didn't - any other ideas?

 

Thanks for the help so far (that was very fast).

 

 

Adam

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.