Follow us on Twitter!
Few are those who can see with their own eyes and hear with their own hearts. - Albert Einstein
Thursday, April 17, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 15
Guests Online: 15
Members Online: 0

Registered Members: 82813
Newest Member: VesuviusSentinel
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

php curl log in


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 29-06-09 03:58
i'm quite new to curl, i need to log in to a certain page every hour. i had a curl code that would submit the details and log me in fine using

Code
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'form1=username&form2=stuff.....');





the webiste has about 4 forms that need to be filled in to submit. but 3 of them are hidden and dont really do anything


i realised this morning that the 3 hidden form names & some of their values needed to log in are changed every 24 hours, probably to stop exactly what i want to do.

so instead of me sending the form names are values myself (because they are always changing) i imagine there would be a simpler code to just go to the webpage, enter in 1 form, click submit, and let the other 3 hidden ones stay as per normal.

any ideas? or help?
cheers
Author

RE: php curl log in


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 29-06-09 10:38
You can use curl to first access the login page and then extract the other 3 forms.
Store the login page in a variable and use php functions to find the values.


Author

RE: php curl log in


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 29-06-09 13:56
okay thanks, i will practice with curl a bit more and figure it out
Author

RE: php curl log in

ranma
Member



Posts: 273
Location: Behind a sphere
Joined: 27.08.05
Rank:
Active User
Posted on 29-06-09 17:21
Hey, you want some code I used for making a bot to play a browser game?


Wisdom spared is wisdom squared.
Author

RE: php curl log in


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-06-09 12:51
sure, i will have a look through and see if i understand how it works
Author

RE: php curl log in

ranma
Member



Posts: 273
Location: Behind a sphere
Joined: 27.08.05
Rank:
Active User
Posted on 30-06-09 16:15
Here it goes. It might be a bit confusing, but that's because it uses specifics of the website I coded it for. For example, to log in I have to get some hidden values and then log in, which is I guess what you are trying to do. If you have any questions, ask.

Code
<?php

//Predefined variables

$server="http://s7.travian.us";
$userlogin="user";
$passlogin="pass";


//Get login page source

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $server."/login.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$loginsource = curl_exec($curl);
curl_close($curl);


//Parse login page source for input names

$text=strstr($loginsource,'<input type="hidden" name="login" value="');
$text=substr($text,strlen('<input type="hidden" name="login" value="'));
$placel=strpos($text,'"');
$login=substr($text, 0, $placel);
$text=strstr($text,'<input class="fm fm110" type="text" name="');
$text=substr($text,strlen('<input class="fm fm110" type="text" name="'));
$placeun=strpos($text,'"');
$username=substr($text, 0, $placeun);
$text=strstr($text,'<input class="fm fm110" type="password" name="');
$text=substr($text,strlen('<input class="fm fm110" type="password" name="'));
$placeup=strpos($text,'"');
$userpassword=substr($text, 0, $placeup);
$text=strstr($text,'<input type="hidden" name="');
$text=substr($text,strlen('<input type="hidden" name="'));
$placeo=strpos($text,'"');
$other=substr($text, 0, $placeo);
$text=strstr($text,'value="');
$text=substr($text,strlen('value="'));
$placeo2=strpos($text,'"');
$other2=substr($text, 0, $placeo2);


//Send post variables

$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, $server."/dorf1.php");
curl_setopt($curl2, CURLOPT_POST, 1);
curl_setopt($curl2, CURLOPT_POSTFIELDS, "w=&login=".$login."&".$username."=".$userlogin."&".$userpassword."=".$passlogin."&".$other."=".$other2."&s1=login");
curl_setopt($curl2, CURLOPT_HEADER, 1);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
$result2 = curl_exec($curl2);
curl_close($curl2);
$text2=strstr($result2,'Set-Cookie:');
$text2=substr($text2,strlen('Set-Cookie:'));
$placec=strpos($text2,';');
$thecookie=substr($text2, 0, $placec);


echo "<br><br>Resource Production:
<br><br>
Wood: ".$prodwood." per hour
<br>Clay: ".$prodclay." per hour
<br>Iron: ".$prodiron." per hour
<br>Wheat: ".$prodwheat." per hour<br><br>";


//Use cookie to get source of dorf2.php

$curl4 = curl_init();
curl_setopt($curl4, CURLOPT_URL, $server."/dorf2.php");
curl_setopt($curl4, CURLOPT_COOKIE,$thecookie);
curl_setopt($curl4, CURLOPT_RETURNTRANSFER, 1);
$result4 = curl_exec($curl4);
curl_close($curl4);

//Use sources to get building location and level

$text3=$result3;
for($buildnum=1;$buildnum<=18;$buildnum++)
{
$text3=strstr($text3,'shape="circle" title="');
$text3=substr($text3,strlen('shape="circle" title="'));
$building[$buildnum]=$buildnum."_".
substr($text3, 0, strpos($text3,' level'))."_".
substr($text3, strpos($text3,' level ')+strlen(' level '), strpos($text3,'"><area ')-strpos($text3,' level ')-strlen(' level '));
//$text3=strstr($text3,'level');  //Moves forward for next resource field to catch
echo $building[$buildnum]."<br>";
}

for($buildnum=19;$buildnum<=40;$buildnum++)
{
$text4=strstr($result4,'<area href="build.php?id='.$buildnum.'" title="');
$text4=substr($text4,strlen('<area href="build.php?id='.$buildnum.'" title="'));
$building[$buildnum]=$buildnum."_";
if(strpos(substr($text4, 0, strpos($text4,'"')),' level')===FALSE)
{
$building[$buildnum]=$building[$buildnum].'Building site_0';
}
else
{
$building[$buildnum]=$building[$buildnum].substr($text4, 0, strpos($text4,' level'))."_".
substr($text4, strpos($text4,' level ')+strlen(' level '), strpos($text4,'" coords="')-strpos($text4,' level ')-strlen(' level '));
}
echo $building[$buildnum]."<br>";
}

?>





Wisdom spared is wisdom squared.