Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
Client stuck at 76% / Voting API too many re-directs [HelpRequest]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MayoMayn" data-source="post: 397105" data-attributes="member: 71840"><p>[PHP]</p><p><?php</p><p></p><p>class FindRetros</p><p>{</p><p></p><p> </p><p>private $pageName, $requestTimeout, $apiPath, $settings;</p><p></p><p> public function __construct(array $settings)</p><p> {</p><p> $this->pageName = $settings['pagename'];</p><p> $this->requestTimeout = $settings['timeout'];</p><p> $this->apiPath = $settings['api'];</p><p> }</p><p></p><p> public function getIP()</p><p> {</p><p> $ip = $_SERVER['REMOTE_ADDR'];</p><p> // In case the server is using CloudFlare, `REMOTE_ADDR` receives the server's IP itself and not the user's. `HTTP_CF_CONNECTING_IP` is deprecated and full of exploits.</p><p> if(isset($_SERVER['HTTP_FORWARDED'])) {</p><p> $ip = $_SERVER['HTTP_FORWARDED'];</p><p> } elseif(isset($_SERVER['HTTP_X_FORWARDED'])) {</p><p> $ip = $_SERVER['HTTP_X_FORWARDED'];</p><p> }</p><p> return $ip;</p><p> }</p><p></p><p> public function hasClientVoted()</p><p> {</p><p> if(!$this->_isVoteCookieSet()) {</p><p> $urlRequest = $this->apiPath . 'validate.php?user=' . $this->pageName . '&ip=' . $this->getIP();</p><p> $dataRequest = $this->_makeCurlRequest($urlRequest);</p><p></p><p> if(in_array($dataRequest, [1, 2])) {</p><p> $this->_setVoteCookie();</p><p> return true;</p><p> } elseif($dataRequest == 3) {</p><p> return false;</p><p> } else {</p><p> /* There's something wrong with FindRetros, so we will mark the user as voted and have them proceed as if they voted. */</p><p> $this->_setVoteCookie();</p><p> return true;</p><p> }</p><p> }</p><p> return true;</p><p> }</p><p></p><p> public function redirectClientToVote()</p><p> {</p><p> header('Location: ' . $this->apiPath . 'rankings/vote/' . $this->pageName);</p><p> exit();</p><p></p><p> }</p><p></p><p> private function _makeCurlRequest($url)</p><p> {</p><p> if(function_exists('curl_version')) {</p><p> $curl = curl_init();</p><p></p><p> curl_setopt($curl, CURLOPT_URL, $url);</p><p> curl_setopt($curl, CURLOPT_HEADER, 0);</p><p> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);</p><p> curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);</p><p> curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);</p><p> curl_setopt($curl, CURLOPT_TIMEOUT, $this->requestTimeout);</p><p> curl_setopt($curl, CURLOPT_USERAGENT, 'FindRetros Vote Validator');</p><p></p><p> $requestData = curl_exec($curl);</p><p></p><p> curl_close($curl);</p><p> } else {</p><p> $requestData = stream_context_create(['http' => ['timeout' => $this->requestTimeout]]);</p><p></p><p> return @file_get_contents($url, 0, $requestData);</p><p> }</p><p> return $requestData;</p><p> }</p><p></p><p> private function _setVoteCookie()</p><p> {</p><p> $rankingsResetTime = $this->_getRankingsResetTime();</p><p></p><p> setcookie('voting_stamp', $rankingsResetTime, $rankingsResetTime);</p><p></p><p> }</p><p></p><p> private function _isVoteCookieSet()</p><p> {</p><p> if(isset($_COOKIE['voting_stamp'])) {</p><p> if($_COOKIE['voting_stamp'] == $this->_getRankingsResetTime()) {</p><p> return true;</p><p> } else {</p><p> setcookie('voting_stamp', '');</p><p> return false;</p><p> }</p><p> }</p><p> return false;</p><p> }</p><p></p><p> private function _getRankingsResetTime()</p><p> {</p><p> $serverDefaultTime = date_default_timezone_get();</p><p></p><p> $rankingsResetTime = mktime(0, 0, 0, date('n'), date('j') + 1);</p><p> </p><p> date_default_timezone_set($serverDefaultTime);</p><p> </p><p> return $rankingsResetTime;</p><p> }</p><p>}</p><p>[/PHP]</p><p>Call the voting here as an external page.</p><p>[PHP]</p><p><?php</p><p>require_once A . M . 'findretros/api.php';</p><p></p><p>$settings = [</p><p> 'pagename' => "Robbo",</p><p> 'timeout' => 5,</p><p> 'api' => "https://findretros.com/"</p><p>];</p><p></p><p>$FindRetros = new FindRetros($settings);</p><p></p><p>if(!isset($_GET['redirect'])) {</p><p> $_GET['redirect'] = "client";</p><p>}</p><p></p><p>$continue = true;</p><p></p><p>if(!$FindRetros->hasClientVoted()) {</p><p> $FindRetros->redirectClientToVote();</p><p> $continue = false;</p><p>}</p><p></p><p>if($continue == true) {</p><p> header('Location: '.$config->hotel('url').'/'.$_GET['redirect']);</p><p> exit();</p><p>}</p><p>?></p><p>[/PHP]</p><p>You should really read their documentation bro, your script is wayyy outdated compared to this one.</p></blockquote><p></p>
[QUOTE="MayoMayn, post: 397105, member: 71840"] [PHP] <?php class FindRetros { private $pageName, $requestTimeout, $apiPath, $settings; public function __construct(array $settings) { $this->pageName = $settings['pagename']; $this->requestTimeout = $settings['timeout']; $this->apiPath = $settings['api']; } public function getIP() { $ip = $_SERVER['REMOTE_ADDR']; // In case the server is using CloudFlare, `REMOTE_ADDR` receives the server's IP itself and not the user's. `HTTP_CF_CONNECTING_IP` is deprecated and full of exploits. if(isset($_SERVER['HTTP_FORWARDED'])) { $ip = $_SERVER['HTTP_FORWARDED']; } elseif(isset($_SERVER['HTTP_X_FORWARDED'])) { $ip = $_SERVER['HTTP_X_FORWARDED']; } return $ip; } public function hasClientVoted() { if(!$this->_isVoteCookieSet()) { $urlRequest = $this->apiPath . 'validate.php?user=' . $this->pageName . '&ip=' . $this->getIP(); $dataRequest = $this->_makeCurlRequest($urlRequest); if(in_array($dataRequest, [1, 2])) { $this->_setVoteCookie(); return true; } elseif($dataRequest == 3) { return false; } else { /* There's something wrong with FindRetros, so we will mark the user as voted and have them proceed as if they voted. */ $this->_setVoteCookie(); return true; } } return true; } public function redirectClientToVote() { header('Location: ' . $this->apiPath . 'rankings/vote/' . $this->pageName); exit(); } private function _makeCurlRequest($url) { if(function_exists('curl_version')) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_TIMEOUT, $this->requestTimeout); curl_setopt($curl, CURLOPT_USERAGENT, 'FindRetros Vote Validator'); $requestData = curl_exec($curl); curl_close($curl); } else { $requestData = stream_context_create(['http' => ['timeout' => $this->requestTimeout]]); return @file_get_contents($url, 0, $requestData); } return $requestData; } private function _setVoteCookie() { $rankingsResetTime = $this->_getRankingsResetTime(); setcookie('voting_stamp', $rankingsResetTime, $rankingsResetTime); } private function _isVoteCookieSet() { if(isset($_COOKIE['voting_stamp'])) { if($_COOKIE['voting_stamp'] == $this->_getRankingsResetTime()) { return true; } else { setcookie('voting_stamp', ''); return false; } } return false; } private function _getRankingsResetTime() { $serverDefaultTime = date_default_timezone_get(); $rankingsResetTime = mktime(0, 0, 0, date('n'), date('j') + 1); date_default_timezone_set($serverDefaultTime); return $rankingsResetTime; } } [/PHP] Call the voting here as an external page. [PHP] <?php require_once A . M . 'findretros/api.php'; $settings = [ 'pagename' => "Robbo", 'timeout' => 5, 'api' => "https://findretros.com/" ]; $FindRetros = new FindRetros($settings); if(!isset($_GET['redirect'])) { $_GET['redirect'] = "client"; } $continue = true; if(!$FindRetros->hasClientVoted()) { $FindRetros->redirectClientToVote(); $continue = false; } if($continue == true) { header('Location: '.$config->hotel('url').'/'.$_GET['redirect']); exit(); } ?> [/PHP] You should really read their documentation bro, your script is wayyy outdated compared to this one. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Client stuck at 76% / Voting API too many re-directs [HelpRequest]
Top