Help with PHP login script

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Help with PHP login script

Re: Help with PHP login script

Post by Pulover » 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"];

Re: Help with PHP login script

Post by Pulover » 10 Oct 2013, 15:39

Thanks! I'll try it and let you know how it goes!

Re: Help with PHP login script

Post by tank » 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
    );
}

Re: Help with PHP login script

Post by Pulover » 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!

Re: Help with PHP login script

Post by tank » 10 Oct 2013, 15:01

Sorry havent forgotten you been busy with work. Ill fix you up before saturday

Re: Help with PHP login script

Post by joedf » 10 Oct 2013, 13:45

tank got it, right in the "noodles"... :P

Re: Help with PHP login script

Post by tank » 09 Oct 2013, 13:57

perfect

Re: Help with PHP login script

Post by Pulover » 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.

Re: Help with PHP login script

Post by tank » 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

Help with PHP login script

Post by Pulover » 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!

Top