Jump to content

[cURL]Login to a website and get the content of a page


YBthebest

Recommended Posts

Hello!

 

I would like to use cURL to login to the website: lockerz.com

 

I have some code, but it doesn't seem to work:

<?php
// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://lockerz.com/auth/login');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, '[email protected]&password-password=PASSWPRD');

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);

// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL, 'http://lockerz.com/auction');

// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch); 
echo $content;
?>

 

Thank you very much if you can help!

How about instead of posting a link that goes to a 301 error message, you tell us what is happening, versus what you expect to happen? Describe what you mean by "it doesn't seem to work".

Sorry for that!

 

Well the problem it, it should show me the page with the auctions (prizes) but it shows me the 301 ( it's on Lockerz.com's server, you can see that at the bottom of the page ). Maybe the login is not OK? I don't really know cURL very well.

 

Thank you so much...

I'm by no means a curl expert either, but since you aren't setting a user agent string, I believe it's possible the server thinks a spambot or other "bad" user is attempting to log in, and tossing you aside.

is this section editable to user and pass? Becuase i tried user and made it for my forums with no luck

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, '[email protected]&password-password=PASSWPRD');

 

I guess im asking....why does it say email-email? are these fields to declare it then what the login refers it as? if so in which order?

I found this

<label>Username *<br />
        <input type="text" name="log" id="user_login" class="input" value="" size="20" tabindex="10" /></label>
    </p>

    <p>
       <label>Password<br />
        <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
    </p>

 

So does that mean for "e-mail-email=" i use "log=" on user

and "password=password=" i use "pwd=" ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.