Join us at IRC!
It is never to LATE to become what you never WERE.
Friday, May 25, 2012
Navigation
Members Online
Total Online: 33
Web Spiders: 15
Guests Online: 32
Members Online: 1

Registered Members: 70208
Newest Member: andresuran
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

php curl log in

wrecked
Member

Posts: 4
Location:
Joined: 20.09.08
Rank:
Newbie
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

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

c4p_sl0ck
Member



Posts: 380
Location: Sweden‮‭
Joined: 17.09.06
Rank:
God
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.



c4p_sl0ck@hotmail.com
Author

RE: php curl log in

wrecked
Member

Posts: 4
Location:
Joined: 20.09.08
Rank:
Newbie
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: 269
Location: Behind a sphere
Joined: 27.08.05
Rank:
HBH Guru
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

wrecked
Member

Posts: 4
Location:
Joined: 20.09.08
Rank:
Newbie
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: 269
Location: Behind a sphere
Joined: 27.08.05
Rank:
HBH Guru
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.

<?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.
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.