Hallo,
hier ein kleiner Release:
Mit dieser Klasse könnt ihr prüfen, ob eine Treasure schon gekauft wurde oder nicht. ([Only registered and activated users can see links. Click Here To Register...])
Bei Username muss ein Epvp Accountname und bei Password ein Epvp Password eingetragen werden
Anschließen muss einfach dieser Code ausgeführt werden:
Diese Klasse könnt ihr in euren Projekten verwenden.
Grüße
~ JWonderpig ~
hier ein kleiner Release:
Mit dieser Klasse könnt ihr prüfen, ob eine Treasure schon gekauft wurde oder nicht. ([Only registered and activated users can see links. Click Here To Register...])
Bei Username muss ein Epvp Accountname und bei Password ein Epvp Password eingetragen werden
PHP Code:
<?php
/**
* This class performs the login to the site an determines the treasure state
*/
class TreasureCheck {
/**
* Forum URL
* @var string
*/
private $url = "http://www.elitepvpers.com/forum/";
/**
* Treasure Link
* @var string
*/
private $treasure = "http://www.elitepvpers.com/theblackmarket/treasure/";
/**
* Username
* @var string
*/
private $username = "";
/**
* Password
* @var string
*/
private $password = "";
/**
* Content of treasure page
* @var string
*/
private $treasureContent = null;
/**
* Status of treasure
* @var boolean
*/
private $treasureAvailable = false;
/**
* Requires Treasure URL as parameter
* @param string $url
*/
public function __construct($url) {
//add treasure id to the treasure link
$this->treasure = $url;
//perform login + request
$this->treasureContent = $this->performRequest();
//check if treasure is avaiable
$this->parseTreasureStatus();
}
/**
* Returns Treasure status
* @return boolean
*/
public function getTreasureStatus()
{
return $this->treasureAvailable;
}
/**
* Parsed Treasure ID form URL
* @param string $url
* @return boolean
*/
private function parseTreasureID($url)
{
$path = parse_url($url);
$id = explode('/', $path['path']);
return $id[3];
}
/**
* Returns status of Treasure
* @return boolean
*/
private function parseTreasureStatus()
{
libxml_use_internal_errors(true);
//create new DOM Object
$dom = new DOMDocument;
//Load HTml into the DOM object
$dom->loadHTML($this->treasureContent);
//remove white spaces
$dom->preserveWhiteSpace = false;
//create new XPath Object
$finder = new DOMXPath($dom);
$rows = $finder->query('//*[@class="cwalt"]/table/tr');
//go through each row and check status
foreach ($rows as $row)
{
$cols = $row->getElementsByTagName('td');
if ($cols->item(6)->nodeValue == 'n/a') {
$this->treasureAvailable = true;
return true;
}
$this->treasureAvailable = false;
return false;
}
}
/**
* Performs Elitepvpers Login and returns content of the treasure page
* @return string
*/
private function performRequest() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . 'veri.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . 'veri.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $this->url . 'index.php');
curl_setopt($ch, CURLOPT_URL, $this->url . 'login.php?do=login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "vb_login_username=$this->username&vb_login_password&s=&securitytoken=guest&do=login&vb_login_md5password=" . md5($this->password) . "&vb_login_md5password_utf=" . md5($this->password));
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_REFERER, $this->url . 'login.php?do=login');
curl_setopt($ch, CURLOPT_URL, $this->url . 'clientscript/vbulletin_global.js?v=373');
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_REFERER, $this->url . 'login.php?do=login');
curl_setopt($ch, CURLOPT_URL, $this->url . 'index.php');
$exec = curl_exec($ch);
curl_setopt($ch, CURLOPT_REFERER, $this->url . 'index.php');
curl_setopt($ch, CURLOPT_URL, $this->treasure);
$exec = curl_exec($ch);
return $exec;
}
}
PHP Code:
$tc = new TreasureCheck('url zur treasure');
$tc->getTreasureStatus();
Grüße
~ JWonderpig ~