YBthebest Posted November 22, 2010 Share Posted November 22, 2010 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! Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/ Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 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". Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1137946 Share on other sites More sharing options...
YBthebest Posted November 22, 2010 Author Share Posted November 22, 2010 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... Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138020 Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 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. Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138025 Share on other sites More sharing options...
rusking Posted November 22, 2010 Share Posted November 22, 2010 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? Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138120 Share on other sites More sharing options...
BlueSkyIS Posted November 22, 2010 Share Posted November 22, 2010 those are the names of the fields in the login form, or should be, for example: <input type='text' name='email-email' size='30'> <input type='password' name='password-password' size='30'> Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138122 Share on other sites More sharing options...
rusking Posted November 22, 2010 Share Posted November 22, 2010 ooo ok to the source i go to find these fields Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138132 Share on other sites More sharing options...
rusking Posted November 22, 2010 Share Posted November 22, 2010 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=" ? Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138141 Share on other sites More sharing options...
rusking Posted November 22, 2010 Share Posted November 22, 2010 seems to work. Thank you Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138149 Share on other sites More sharing options...
YBthebest Posted November 23, 2010 Author Share Posted November 23, 2010 Is it rworking for you? How? It still is not working for me...and no that website does not check on the useragent...arghh Still waiting for an answer! Thank you very much, I love you guys Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138481 Share on other sites More sharing options...
rusking Posted November 23, 2010 Share Posted November 23, 2010 I works for me but i only used parts of it. Not the whole thing. I used my website and had it just loginto my forums. i can provide the code if you like but its only portions of the original Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138555 Share on other sites More sharing options...
YBthebest Posted November 24, 2010 Author Share Posted November 24, 2010 Well if it can work for me...yes please ^^ I'm not sure at all, just need something :/ Link to comment https://forums.phpfreaks.com/topic/219452-curllogin-to-a-website-and-get-the-content-of-a-page/#findComment-1138891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.