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 Tutorials
FindRetro's API
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="Joe" data-source="post: 444200" data-attributes="member: 18160"><p>There's probably 500 tutorials on this but people keep asking me.</p><p></p><p>Add 'findretros.php' and 'findretros_config.php' to your skins folder, add the 'client.php' code to the top of your client, or anywhere on your CMS where you want them to vote. <strong>Make sure to edit 'Example' in the findretros_config.php to your FindRetro's server username.</strong></p><p></p><p>[SPOILER="findretros.php"]</p><p>[CODE=php]<?php</p><p>class FindRetros {</p><p> private $pageName, $callTimeout, $usingCloudFlare, $apiPath;</p><p> function __construct() {</p><p> global $_CONFIG;</p><p> $this->pageName = $_CONFIG['pagename'];</p><p> $this->requestTimeout = $_CONFIG['timeout'];</p><p> $this->usingCloudFlare = $_CONFIG['cloudflare'];</p><p> $this->apiPath = $_CONFIG['api'];</p><p> if($this->usingCloudFlare) {</p><p> if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {</p><p> $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];</p><p> }</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=' . $_SERVER['REMOTE_ADDR'];</p><p> $dataRequest = $this->_makeCurlRequest($urlRequest);</p><p> if(in_array($dataRequest, array(1, 2))) {</p><p> $this->_setVoteCookie();</p><p> return true;</p><p> }else if($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> public function redirectClientToVote() {</p><p> header('Location: ' . $this->apiPath . 'rankings/vote/' . $this->pageName);</p><p> exit;</p><p> }</p><p> private function _makeCurlRequest($url) {</p><p> if(function_exists('curl_version')) {</p><p> $curl = curl_init();</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> $requestData = curl_exec($curl);</p><p> curl_close($curl);</p><p> }else{</p><p> $requestData = stream_context_create(array('http' => array('timeout' => $this->requestTimeout)));</p><p> return @file_get_contents($url, 0, $requestData);</p><p> }</p><p> return $requestData;</p><p> }</p><p> private function _setVoteCookie() {</p><p> $rankingsResetTime = $this->_getRankingsResetTime();</p><p> setcookie('voting_stamp', $rankingsResetTime, $rankingsResetTime);</p><p> }</p><p> private function _isVoteCookieSet() {</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> private function _getRankingsResetTime() {</p><p> $serverDefaultTime = date_default_timezone_get();</p><p> date_default_timezone_set('America/Chicago');</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>}[/CODE]</p><p>[/SPOILER]</p><p>[SPOILER="findretros_config.php"]</p><p>[CODE=php]<?php</p><p>$_CONFIG = array(</p><p> /* What is "username" of your page on FindRetros? */</p><p></p><p> 'pagename' => 'Example',</p><p> /* How many seconds should it take to try and reach FindRetros if it's down? */</p><p> 'timeout' => 2,</p><p> /* Are you using CloudFlare? If so, set this to true. */</p><p> 'cloudflare' => false,</p><p> /* Incase FindRetros.com has a new domain, change it below. */</p><p> 'api' => 'https://findretros.com/'</p><p>);[/CODE]</p><p>[/SPOILER]</p><p>[SPOILER="client.php"]</p><p>[CODE=php]<?php</p><p>require_once 'findretros_config.php';</p><p>require_once 'findretros.php';</p><p>$FindRetros = new FindRetros();</p><p>if($FindRetros->hasClientVoted()) {</p><p> echo 'You have voted!';</p><p>}else{</p><p> // echo 'You have yet to vote!';</p><p> $FindRetros->redirectClientToVote();</p><p>}[/CODE]</p><p>[/SPOILER]</p></blockquote><p></p>
[QUOTE="Joe, post: 444200, member: 18160"] There's probably 500 tutorials on this but people keep asking me. Add 'findretros.php' and 'findretros_config.php' to your skins folder, add the 'client.php' code to the top of your client, or anywhere on your CMS where you want them to vote. [B]Make sure to edit 'Example' in the findretros_config.php to your FindRetro's server username.[/B] [SPOILER="findretros.php"] [CODE=php]<?php class FindRetros { private $pageName, $callTimeout, $usingCloudFlare, $apiPath; function __construct() { global $_CONFIG; $this->pageName = $_CONFIG['pagename']; $this->requestTimeout = $_CONFIG['timeout']; $this->usingCloudFlare = $_CONFIG['cloudflare']; $this->apiPath = $_CONFIG['api']; if($this->usingCloudFlare) { if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; } } } public function hasClientVoted() { if(!$this->_isVoteCookieSet()) { $urlRequest = $this->apiPath . 'validate.php?user=' . $this->pageName . '&ip=' . $_SERVER['REMOTE_ADDR']; $dataRequest = $this->_makeCurlRequest($urlRequest); if(in_array($dataRequest, array(1, 2))) { $this->_setVoteCookie(); return true; }else if($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(array('http' => array('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(); date_default_timezone_set('America/Chicago'); $rankingsResetTime = mktime(0, 0, 0, date('n'), date('j') + 1); date_default_timezone_set($serverDefaultTime); return $rankingsResetTime; } }[/CODE] [/SPOILER] [SPOILER="findretros_config.php"] [CODE=php]<?php $_CONFIG = array( /* What is "username" of your page on FindRetros? */ 'pagename' => 'Example', /* How many seconds should it take to try and reach FindRetros if it's down? */ 'timeout' => 2, /* Are you using CloudFlare? If so, set this to true. */ 'cloudflare' => false, /* Incase FindRetros.com has a new domain, change it below. */ 'api' => 'https://findretros.com/' );[/CODE] [/SPOILER] [SPOILER="client.php"] [CODE=php]<?php require_once 'findretros_config.php'; require_once 'findretros.php'; $FindRetros = new FindRetros(); if($FindRetros->hasClientVoted()) { echo 'You have voted!'; }else{ // echo 'You have yet to vote!'; $FindRetros->redirectClientToVote(); }[/CODE] [/SPOILER] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Tutorials
FindRetro's API
Top