View difference between Paste ID: eY7cXsbu and Vh0UE6F1
SHOW: | | - or go back to the newest paste.
1-
* About to connect() to moodle.tsrs.org port 80 (#0)
1+
<?php
2-
*   Trying 125.22.33.149... * connected
2+
3-
* Connected to moodle.tsrs.org (125.22.33.149) port 80 (#0)
3+
function login($username, $password, $url = 'http://moodle.tsrs.org/login/index.php')
4-
> POST /login/index.php HTTP/1.1
4+
{
5-
Host: moodle.tsrs.org
5+
    // Create base headers for use with both requests
6-
Accept: */*
6+
    $parts = parse_url($url);
7-
Accept-Encoding: deflate, gzip
7+
    $baseHeaders = array(
8-
Content-Length: 0
8+
        'Origin: ' . $parts['scheme'] . '://' . $parts['host'],
9-
Content-Type: application/x-www-form-urlencoded
9+
        'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36',
10-
< HTTP/1.1 200 OK
10+
        'Accept: */*',
11-
< Date: Sun, 23 Nov 2014 21:24:29 GMT
11+
    );
12-
< Server: Apache/2.2.20 (Ubuntu) PHP/5.3.2-1ubuntu4.21 with Suhosin-Patch
12+
13-
< X-Powered-By: PHP/5.3.2-1ubuntu4.21
13+
    // Temporary file path for the cookie jar
14-
* Added cookie MoodleSession="g2hajfog95sb5rj3i0tpnkihc0" for domain moodle.tsrs.org, path /, expire 0
14+
    $cookieJar = tempnam('/tmp', $username . '-cookie');
15-
< Set-Cookie: MoodleSession=g2hajfog95sb5rj3i0tpnkihc0; path=/
15+
16-
< Expires: 
16+
    // Make an initial GET request to fetch a fresh set of session cookies
17-
< Cache-Control: private, pre-check=0, post-check=0, max-age=0
17+
    $ch = curl_init($url);
18-
< Pragma: no-cache
18+
19-
* Added cookie MoodleSessionTest="QUKNviKr2I" for domain moodle.tsrs.org, path /, expire 0
19+
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20-
< Set-Cookie: MoodleSessionTest=QUKNviKr2I; path=/
20+
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
21-
* Added cookie MOODLEID_="deleted" for domain moodle.tsrs.org, path /, expire 1385241868
21+
22-
< Set-Cookie: MOODLEID_=deleted; expires=Sat, 23-Nov-2013 21:24:28 GMT; path=/
22+
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar);
23-
* Replaced cookie MOODLEID_="%25ED%25C3%251CC%25B7d" for domain moodle.tsrs.org, path /, expire 1421961869
23+
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
24-
< Set-Cookie: MOODLEID_=%25ED%25C3%251CC%25B7d; expires=Thu, 22-Jan-2015 21:24:29 GMT; path=/
24+
25-
< Content-Script-Type: text/javascript
25+
    curl_setopt($ch, CURLOPT_HTTPHEADER, $baseHeaders);
26-
< Content-Style-Type: text/css
26+
27-
< Content-Language: en
27+
    curl_exec($ch);
28-
< Accept-Ranges: none
28+
    curl_close($ch);
29-
< Vary: Accept-Encoding
29+
30-
< Content-Encoding: gzip
30+
    // Make the actual POST request to attempt login
31-
< Content-Length: 2908
31+
    $data = array(
32-
< Content-Type: text/html; charset=utf-8
32+
        'username' => $username,
33-
< 
33+
        'password' => $password,
34-
* Connection #0 to host moodle.tsrs.org left intact
34+
        'testcookies'=> '1',
35-
* Closing connection #0
35+
    );
36
    $headers = array(
37
        'Referer: ' . $url,
38
    );
39
40
    $ch = curl_init($url);
41
42
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
43
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
44
45
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar);
46
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
47
48
    curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($baseHeaders, $headers));
49
    curl_setopt($ch, CURLOPT_POST, true);
50
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
51
52
    $output = curl_exec($ch);
53
    curl_close($ch);
54
55
    // Remove the temp cookie store
56
    unlink($cookieJar);
57
58
    echo "\n" . $output . "\n";
59
}
60
61
login($_POST['username'], $_POST['password']);