supermerc Posted December 18, 2008 Share Posted December 18, 2008 Hi, I am trying to use cURL to login to a game called outwar, but its not working for me. this is the code I use: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/myaccount.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, 'login_username=username&login_password=password'); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $store = curl_exec ($ch); $str = file_get_contents("http://quiver.outwar.com/myaccount.php"); echo $str; curl_close ($ch); ?> Please help me. Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/ Share on other sites More sharing options...
JonnoTheDev Posted December 18, 2008 Share Posted December 18, 2008 You are using CURL to post to the login form and then using file_get_contents() to retrieve your account page. Why? If your session is stored in cookie.txt then only CURL can use it. You must use CURL to retrieve the pages you wish to access. Think of it as a web browser. To get your page you will need to change your options curl_setopt($ch, CURLOPT_HTTPGET, TRUE); curl_setopt($ch, CURLOPT_POST, FALSE); I would write a function for CURL so you can use in both POST and GET modes. Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-718934 Share on other sites More sharing options...
supermerc Posted December 18, 2008 Author Share Posted December 18, 2008 How would I do that? Also it isnt shown in my code but what I am trying to do is to check the content of a page and look for keywords, if the keyword is in the page then it goes to a page, if not, it keeps refreshing. Like this <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/myaccount.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, 'login_username=username&login_password=password'); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $store = curl_exec ($ch); $str = file_get_contents("http://quiver.outwar.com/myaccount.php"); echo $str; if(stristr($str,'wanhiroeaz')||stristr($str,'crane')||stristr($str,'mistress of the sword')||stristr($str,'Lord of Thugs')||stristr($str,'Rebel of Rallis')||stristr($str,'The collector')) { header("Location: http://www.sounddogs.com/previews/2221/mp3/411348_SOUNDDOGS_AL.mp3");exit(); } else { echo '<meta http-equiv="refresh" content="5" />'; } curl_close ($ch); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-718992 Share on other sites More sharing options...
supermerc Posted December 18, 2008 Author Share Posted December 18, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719208 Share on other sites More sharing options...
supermerc Posted December 19, 2008 Author Share Posted December 19, 2008 bump? Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719399 Share on other sites More sharing options...
shlumph Posted December 19, 2008 Share Posted December 19, 2008 What happens when you echo out $store ? Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719409 Share on other sites More sharing options...
supermerc Posted December 19, 2008 Author Share Posted December 19, 2008 The page is blank... :S Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719412 Share on other sites More sharing options...
supermerc Posted December 19, 2008 Author Share Posted December 19, 2008 scratch that it isnt... Its shows me the page and something tells me You have failed to log in too many times. Please wait 15 minutes and try again. But the username and password are fine. Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719413 Share on other sites More sharing options...
supermerc Posted December 19, 2008 Author Share Posted December 19, 2008 Sorry again, I made a mistake in password, this time it actually worked, it managed to login, now using curl how can I go to this page http://quiver.outwar.com/world.php?suid=55726&serverid=6 and do this part of my code <?php if(stristr($str,'wanhiroeaz')||stristr($str,'crane')||stristr($str,'mistress of the sword')||stristr($str,'Lord of Thugs')||stristr($str,'Rebel of Rallis')||stristr($str,'The collector')) { header("Location: http://www.sounddogs.com/previews/2221/mp3/411348_SOUNDDOGS_AL.mp3");exit(); } else { echo '<meta http-equiv="refresh" content="5" />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/#findComment-719430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.