Показать сообщение отдельно

  #9410  
Старый 14.03.2009, 19:42
Kaimi
Познавший АНТИЧАТ
Регистрация: 23.08.2007
Сообщений: 1,237
С нами: 9851426

Репутация: 1676


По умолчанию

Цитата:
Эм.Я немного не так выразился.Пример авторизации МОЕГО скрипта в соц.сети "вконтакте".Для последующего парсинга своей страницы.
PHP код:
<?
$login     
'test@mail.ru';
$passw     'test';
$browser 'Mozilla 4.0';

$ck login($login$passw);
print 
$ck;

function 
login($acc$pass) {
$acc=urlencode($acc);
$pass=urlencode($pass);

$ret=socket_do("vkontakte.ru","email={$acc}&pass={$pass}","/login.php",$browser,'',1,"POST",'http://vkontakte.ru',1,$pr,$pp);

$ret=substr($ret,0,strpos($ret,"\r\n\r\n"));

if(
strpos($ret,"Location: id")===false) die("err");

preg_match_all("/Set-Cookie: ([\s\S]+); expires=/isU",$ret,$m);
$cook="";
$tcnt=0;
foreach(
$m[1] as $ck)
    {
    
$tcnt++;
    if(
$tcnt==|| strpos($ck,'remixcookietest=')!==false) continue;
    
$cook.=$ck.'; ';
    }

$cook=substr($cook,0,strlen($cook)-2);
return 
$cook;
}

function 
socket_do($host,$vars,$service_uri,$browser,$cookies='',$sread=1,$method='POST',$ref='',$addheaders=1,$proxy=false,$proxyport=0,$HTTP='1.0')
{
  
$ret="";

  if(
$method=='GET' && $vars)
  {
    
$service_uri.='?'.$vars;
    
$vars='';
  }

  
$header="Host: $host\r\n";
  
$header.="User-Agent: $browser\r\n";

  if(
$addheaders==1)
  {
    
$header.="Content-Type: application/x-www-form-urlencoded\r\n";
    
$header.="Content-Length: ".strlen($vars)."\r\n";
  }
  else if(
$addheaders==0)
  {
    
$header.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
    
$header.="Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
    
$header.="Accept-Encoding: \r\n";
    
$header.="Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7\r\n";
  }
  else if(
$addheaders==2)
  {
    
$header.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
    
$header.="Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
    
$header.="Accept-Encoding: \r\n";
    
$header.="Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7\r\n";
    
$header.="Pragma: no-cache\r\n";
    
$header.="Cache-Control: no-cache\r\n";
    
$header.="Content-Length: ".strlen($vars)."\r\n";
    
$header.="Content-Type: application/x-www-form-urlencoded; charset=windows-1251\r\n";
  }
  else if(
$addheaders==3)
  {
    
$header.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
    
$header.="Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
    
$header.="Accept-Encoding: gzip,deflate\r\n";
    
$header.="Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7\r\n";
  }


  if(
$ref$header.="Referer: $ref\r\n";

  
$header.="Connection: close\r\n";

  if(
$cookies)
    
$header.="Cookie: $cookies\r\n";

  
$header.="\r\n";


  if(
$proxy)
  {
    
$addquery="$method http://$host$service_uri  HTTP/$HTTP\r\n";
    
$fp=fsockopen("tcp://".$proxy,$proxyport,$errno,$errstr,30);
  }
  else
  {
    
$addquery="$method $service_uri  HTTP/$HTTP\r\n";
    
$fp=fsockopen("tcp://".$host,80,$errno,$errstr,30);
  }

  
stream_set_timeout($fp,30);

  if(!
$fp)
  {
    print 
"Socket error";
    exit();
  }



  
fputs($fp,$addquery);
  
fputs($fp,$header.$vars);


  if(
$sread)
  {
    while(!
feof($fp))
    {
      
$ret.=fgets($fp128);
    }
  }

  
fclose($fp);



  return 
$ret;
}
?>

Последний раз редактировалось Kaimi; 14.03.2009 в 19:45..
 
Ответить с цитированием