View Single Post
Old 08-16-2009, 12:43 AM   #122 (permalink)
skruf
The Visitor
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
skruf is on a distinguished road
Default

Very interesting thread, a lot of useful scripts here!

I'm trying to make a guild-bank system, but I can't seem to get a workaround the cUrl authentication.

I used Kirks' script, and after a few modification it looks like this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<body>
<?php
if (isset($_POST['submit'])) {

$username = $_POST['username'];
$password = $_POST['password'];

$loginvars = 'accountName=' . $username . '&password=' . $password;

$url = 'https://eu.battle.net/login/login.xml?ref=http%3A%2F%2Feu.wowarmory.com%2Fvault%2Fguild-bank-contents.xml%3Fr%3DTalnivarr%26gn%3DVrede&app=armory';

    $ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $loginvars);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, '../hidden/cookie.txt');
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,15);
	curl_setopt ($ch, CURLOPT_TIMEOUT,30);
    $results = curl_exec($ch);
    curl_close($ch);
	
	if (($results) == ('')){
	
	echo 'Failed to get XML!';
	
	}
	else
	{
	
	$xml = new SimpleXMLElement($results); // line 34
	
	foreach ($xml->guildInfo->guildBank->items->children() as $items) {
    
	$name		 =		$items['name'];
	$icon 		 = 		$items['icon'];
	$id			 =		$items['id'];
	$quantity	 = 		$items['quantity'];
	$subtypeLoc	 =		$items['subtypeLoc'];
	$type	     =		$items['type'];
	
	echo $name;
	echo '<br/>';
	}
	
/*

	

//	$xml = simplexml_load_file('xml.xml');
//	$results = simplexml_load_string($results); 
//	$guildxml = new SimpleXMLElement($results);
	

	
*/

    if (strstr($results, "Invalid account name or password")) {
        echo "Invalid account name or password<br>";
    }
    elseif (strstr($results, "Account name required")) {
        echo "Invalid account name or password<br>";
    }
    elseif (strstr($results, "Password required")) {
        echo "Invalid account name or password<br>";
    }
    elseif (strstr($results, "Authenticator code required")) {
        echo "Invalid Authenticator code<br>";
    }
    elseif (strstr($results, "Login failed")) {
        echo "Invalid account name or password<br>";
    }
    else {
        echo $results;
	}
}
}
else {
?>
<form action="#" id="loginForm" method="post">

Account Name<input id="username"name="username" type="text" /><br>

Password<input id="password" name="password" type="password" /><br>

<input type="submit" name="submit" value="Submit">

</form>
<?php
}
?>
</body> 
</html>
The $results variable is emtpy. If I run the script without the IF, I get this errormessage:

Code:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\bank\test.php:34 Stack trace: #0 C:\xampp\htdocs\bank\test.php(34): SimpleXMLElement->__construct('') #1 {main} thrown in C:\xampp\htdocs\bank\test.php on line 34
Now my experience with cUrl is pretty limited, so I might do some obvious mistake here..

Any ideas?
skruf is offline  
Reply With Quote