Help with PHP login script

Discuss other programming languages besides AutoHotkey
User avatar
Pulover
Posts: 366
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Help with PHP login script

09 Oct 2013, 13:21

I'm trying to make a script to login into a particular website. Tmplinshi was kind enough to help get a working version in ahk but I think it will be better to port it to PHP to run it from a linux server.
Unfortunately, for some reason I don't understand, it's not working.

If anyone here knows PHP well and would like to help me I can send the script with login and password via pm.

Thanks!
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
tank
Posts: 2775
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Help with PHP login script

09 Oct 2013, 13:46

does the login expect post or get?
if get you can easily use

Code: Select all

header( 'Location: http://example.com/page?username=something&password=somepassword .... other params');
If post let me know i have some code somewhere that i will dig up
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
Pulover
Posts: 366
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Help with PHP login script

09 Oct 2013, 13:55

Thanks for the reply, tank!

I'm using POST to send the login information but I need to use GET before to retrieve a token. I've used wireshark to intercept the messages from both ahk and php, and although they seem identical I always get the login page in response when using php. I've tried with and without curl, following examples on the internet.

I'll send you a link to the script via pm.

Thanks again.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
tank
Posts: 2775
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Help with PHP login script

09 Oct 2013, 13:57

perfect
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
joedf
Posts: 7341
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Help with PHP login script

10 Oct 2013, 13:45

tank got it, right in the "noodles"... :P
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
tank
Posts: 2775
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Help with PHP login script

10 Oct 2013, 15:01

Sorry havent forgotten you been busy with work. Ill fix you up before saturday
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
Pulover
Posts: 366
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Help with PHP login script

10 Oct 2013, 15:17

tank wrote:Sorry havent forgotten you been busy with work. Ill fix you up before saturday
I'll be glad if you could take a look, but me and a bunch of friends have been trying everything since yesterday and nothing seems to work...
I believe the site must be blocking PHP/cURL. I can get it working on ahk (even got it using the COM object now) but no luck with PHP.

I've decided to try another language and started learning and converting it to Python today. And I'm glad to inform that I have successfully created a script to log in the website using Python, thanks to the requests library (already tested on ubuntu as well). :D

I suppose PHP would still be a better option, though. So if you do find a way, please let me know! But my hopes are low at this point...
I hope I can integrate PHP and Python now!
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
tank
Posts: 2775
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Help with PHP login script

10 Oct 2013, 15:27

I have had better luck with this instead of cURL

Code: Select all

function post_request($url, $data, $referer='') {
 
    // Convert the data array into URL Parameters like a=b&foo=bar etc.
    $data = http_build_query($data);
 
    // parse the given URL
    $url = parse_url($url);
 
    if ($url['scheme'] != 'http') { 
        die('Error: Only HTTP request are supported !');
    }
 
    // extract host and path:
    $host = $url['host'];
    $path = $url['path'];
 
    // open a socket connection on port 80 - timeout: 30 sec
    $fp = fsockopen($host, 80, $errno, $errstr, 30);
 
    if ($fp){
 
        // send the request headers:
        fputs($fp, "POST $path HTTP/1.1\r\n");
        fputs($fp, "Host: $host\r\n");
 
        if ($referer != '')
            fputs($fp, "Referer: $referer\r\n");
 
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: ". strlen($data) ."\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $data);
 
        $result = ''; 
        while(!feof($fp)) {
            // receive the results of the request
            $result .= fgets($fp, 128);
        }
    }
    else { 
        return array(
            'status' => 'err', 
            'error' => "$errstr ($errno)"
        );
    }
 
    // close the socket connection:
    fclose($fp);
 
    // split the result header from the content
    $result = explode("\r\n\r\n", $result, 2);
 
    $header = isset($result[0]) ? $result[0] : '';
    $content = isset($result[1]) ? $result[1] : '';
 
    // return as structured array:
    return array(
        'status' => 'ok',
        'header' => $header,
        'content' => $content
    );
}
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
User avatar
Pulover
Posts: 366
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Help with PHP login script

10 Oct 2013, 15:39

Thanks! I'll try it and let you know how it goes!
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Pulover
Posts: 366
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Help with PHP login script

10 Oct 2013, 17:44

I seem to be getting a wrong result... :roll:
The 'status' is ok but 'content' shows the number 139, then I get sent to the login page just like before...

Am I calling it correctly?

Code: Select all

$data =
array
(
	'username' => $login,
	'password' => $pass,
	'perslogin' => 'Y',
	'token' => $token,
	'tprefs1' => '',
	'tprefs2' => ''
);
$response = post_request($loginUrl, $data, $loginUrl);
echo $response["content"];
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 3 guests