Jump to content

[SOLVED] cURL to login to a site


supermerc

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/137544-solved-curl-to-login-to-a-site/
Share on other sites

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.

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);

?>

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" />';
}
?>

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.