Jump to content

Need help with Login and get contents


MasterK

Recommended Posts

I am trying to login to this website and pull data from it. But it doesn't seem to be working and I believe its because of the way their Login for is.

 

<form method=POST ACTION="/index.php?">

<table border=0 id="tblLogin" width="100%">

<tr>

<td id="tdLogin" style="text-align: center">Please Enable Scripts To Log In</td>

</tr>

 

</table>

<script type="text/javascript" language="javascript">

var tblLogin = document.getElementById("tdLogin");

if (tblLogin) {

var strForm = '<table border="0">';

strForm = strForm + '<tr><td>Username:</td><td><input name="U"></td></tr>';

strForm = strForm + '<tr><td>Password:</td><td><input name="P" type="Password"></td></tr>';

strForm = strForm + '<tr><td colspan="2" align="center"><input name="sublogin" id="sublogin" type="submit" value="Login"></td></tr>';

strForm = strForm + '<tr><td colspan="2" align="center"><a href="lostpw.php">Reset My Password</a></td></tr>';

strForm = strForm + '</table>';

 

tblLogin.innerHTML = strForm;

//<tr><td colspan="2" align="center"><a href="servers.php">Change Servers</a></td></tr>

}

/*

var tdReset = document.getElementById("tdReset_PW");

if (tdReset) {

tdReset.innerHTML = '<a href="lostpw.php">Reset My Password</a>';

}

*/

</script>

</form>

 

The code I'm trying to use....

$url = 'URL'; // The URL to the accountmanagement page
$f1 = 'accnr'; // Name of field1(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$f2 = 'pass'; // Name of field2(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$v1 = $_POST['acc']; // Value of field1(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$v2 = $_POST['pw']; // Value of field2(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$find = 'Welcome to your account'; // String to search for in the page you've logged in on
$postchars = http_build_query( array($f1 => $v1, $f2 => $v2) );

$stream = stream_context_create( array('http' => array('method' => 'POST', 'header'  => 'Content-Type: application/x-www-form-urlencoded', 'content' =>  htmlspecialchars_decode( $postchars ) ) ) ); // Creates an array of the sourcecode, and inputs the values of the field1 and field2

$content = file_get_contents($url, false, $stream); // Gets the sourcecode from the new page that is loaded after the input of the values.

$search = strpos($content, $find); // Search the sourcecode for the specific string in the variable "find"

if($search === false){
echo 'The login seems to be incorrect. Please try again, or check if you have a valid account';
} // If the string wasn't found
else {
echo 'Your account is valid!';
}  // If the string was found 

*note* I know that doesn't pull the data, but I'm sure I can edit it to do that easy enough

 

 

 

Thanks for any help!  :D

 

Link to comment
https://forums.phpfreaks.com/topic/198799-need-help-with-login-and-get-contents/
Share on other sites

Why doesn't it work? What happens instead?

 

Well with the script I posted, It comes back with the "The login seems to be incorrect. Please try again, or check if you have a valid account" because It could not find the text string which would be there If it logged in.

 

Whats suppose to happen?

 

With that script its supposed, return "Your account is valid!"

 

What do you mean trying to login to "this" website.

Is it YOUR website?

 

Sorry, this website, I just meant a general website. No it is not my website. It is Playerdex, a website to see your Pokemon/Badges etc for a Pokemon MMORPG. I created a fan site for it, and am Trying to create a script that logs into an account so I can have access to pull data from the Members only section, I have gotten it OKd by the Developers as long as I can figure out how to get it to work.

Try doing a search on google, "how to enable javascript on my browser" as I believe it's a browser issue, rather than a "script" issue

 

Uhm, No. I'm not stupid, Really I'm not, when I go to the website in my browser the login is fine. I go into Tools > Options > and the "Enable Javascript" is checked  :-\

Alright let me try to explain.

 

First. I messed up, I was searching for "Please enable scripts" but I was tired and didn't realize it searches the source and its there no matter what. So Ignore that, Its showing the Login form just fine.

 

But, When I search for something that is only shown when you are NOT logged in such as "Reset my password" It comes back as found. Which means its not logging in

 

So the problem is, The script is not logging into the site

 

Here is my coding, All the information is correct so you can try it out

<?
$url = 'http://www.playerdex.com/index.php?'; // The URL to the accountmanagement page
$f1 = 'U'; // Name of field1(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$f2 = 'P'; // Name of field2(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$v1 = 'sweetiepie'; // Value of field1(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$v2 = 'trin1224'; // Value of field2(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$find = 'Reset My Password'; // String to search for in the page you've logged in on
$postchars = http_build_query( array($f1 => $v1, $f2 => $v2) );

$stream = stream_context_create( array('http' => array('method' => 'POST', 'header'  => 'Content-Type: application/x-www-form-urlencoded', 'content' =>  htmlspecialchars_decode( $postchars ) ) ) ); // Creates an array of the sourcecode, and inputs the values of the field1 and field2

$content = file_get_contents($url, false, $stream); // Gets the sourcecode from the new page that is loaded after the input of the values.

$search = strpos($content, $find); // Search the sourcecode for the specific string in the variable "find"

if($search === false){
echo 'The login seems to be incorrect. Please try again, or check if you have a valid account <br> Found Reset My Password on the page!';
} // If the string wasn't found
else {
echo 'Your account is valid! Did not find Reset My Password on the page';
}  // If the string was found
?>

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.