ANTICHAT

ANTICHAT (https://forum.antichat.io/index.php)
-   PHP (https://forum.antichat.io/forumdisplay.php?f=37)
-   -   Вопрос по скрипт ВК (https://forum.antichat.io/showthread.php?t=186622)

IgrikX 13.03.2010 23:24

Вопрос по скрипт ВК
 
Написал функцию на php авторизации ВК. Потом написал функцию перехода на другую странцу.
Первая функцию принимает параметры логин и пароль. Вторая поисковое слово. Почему при переходе во вторую функцию авторизация теряется? Вроде кукисы считываю.
PHP код:

function vk_login($Email,$Password)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt($ch,CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_ENCODING,'gzip,deflate');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'C:/WebServers/home/test1.ru/www/cookies.txt');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
//GET vkontakte.ru/login.php
curl_setopt ($ch, CURLOPT_URL, 'http://vkontakte.ru/login.php');
$body = curl_exec($ch);
//POST vkontakte.ru/login.php
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "op=a_login_attempt");
curl_setopt ($ch, CURLOPT_URL, 'http://vkontakte.ru/login.php');
$body = curl_exec($ch);
//POST login.vk.com/
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "act=login&success_url=&fail_url=&try_to_login=1&to=&vk=&email=".$Email."&pass=".$Password."&expire=");
curl_setopt ($ch, CURLOPT_URL, 'http://login.vk.com/');
$body = curl_exec($ch); 
curl_close($ch);  
}

//---- Функция поиска музыки Вконтакте
function search_music($text)// параметр - поисковая фраза
{
$ch = curl_init($ch);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'C:/WebServers/home/test1.ru/www/cookies.txt');
// переходим на страницу поиска музыки и извлекаем hash и какие-то другие значения
curl_setopt($ch, CURLOPT_URL, 'http://vkontakte.ru/gsearch.php?section=audio&q='.$text);
$body = curl_exec($ch);
curl_close($ch); 
preg_match_all("#aid:(\d+),oid:(\d+),hash:'(\w+)'}\);return false;\">#",$body,$arr);//регулярка извлекает параметры песни
return $arr;
} 


b3 14.03.2010 04:20

Авторизация омг
PHP код:

function vk_login($email, $pass) {

    
$ch = curl_init('http://login.vk.com/?act=login');
    
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6');
    
curl_setopt($ch, CURLOPT_REFERER, 'http://vkontakte.ru/index.php');
    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
curl_setopt($ch, CURLOPT_POST, 1);
    
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email='.urlencode($email).'&pass='.urlencode($pass).'&expire=&vk=');
    
$errno = curl_errno($ch);
    
$error = curl_error($ch);
    
$res = curl_exec($ch);
    if(
$errno > 0) {
    return 
$errno.':'.$error;    
    } else {
    if(
preg_match('#id=\'s\' value=\'(.*)\'#', $res, $m))
    return 
$m[1];
    else return 
false;
    }

} 

Цитата:

curl_setopt($ch, CURLOPT_COOKIEJAR, 'C:/WebServers/home/test1.ru/www/cookies.txt');
Зачем так путь указывать, пиши просто './cook'


Время: 18:34