-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAskFM.class.php
64 lines (60 loc) · 1.74 KB
/
AskFM.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class AskFM {
public $username;
public $password;
function getLoginPage() {
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_URL => "http://ask.fm/session/new",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true
));
$response = curl_exec($c);
curl_close($c);
preg_match_all("/^Set-Cookie:\s*([^;]*)/mi", $response, $cookies);
$cookie=join(";", $cookies[1]);
return array($response, $cookie);
}
function getAuthenticityToken($source)
{
preg_match("/name=\"authenticity_token\" type=\"hidden\" value=\"(.*?)\"/", $source, $result);
return $result[1];
}
function postLogin($authenticity_token, $cookie)
{
$post = "authenticity_token=".rawurlencode($authenticity_token)."&login=".$this->username."&password=".$this->password."&commit=Masuk";
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_URL => "http://ask.fm/session",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_COOKIE => $cookie
));
$response = curl_exec($c);
curl_close($c);
preg_match_all("/^Set-Cookie:\s*([^;]*)/mi", $response, $cookies);
$cookie=join(";", $cookies[1]);
return $cookie;
}
function postLike($authenticity_token, $cookie, $username, $id)
{
$post = "authenticity_token=".$authenticity_token;
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_URL => "http://ask.fm/likes/".username."/question/".$id."/add",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_COOKIE => $cookie
));
$result = curl_exec($c);
curl_close($c);
return $result;
}
}