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 Releases
CMS Releases
[Laravel] FindRetros Voting Validator
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="Jerry" data-source="post: 429851" data-attributes="member: 35321"><p>Hi,</p><p></p><p>A few people have asked me to set this up for them since they were having issues implementing the voting validator to their Laravel application, so I'm going to release it here. I did not code it myself, all I did was make a new class and copy and pasted the code from <a href="https://github.com/FindRetros/Vote-Validator/" target="_blank">https://github.com/FindRetros/Vote-Validator/</a>.</p><p></p><p>Steps:</p><p>1. Make a new PHP file called <strong>FindRetros.php</strong> in the App\Http folder.</p><p></p><p>2. Paste this code to the file (<strong>replace 'pageName' with your FindRetros page name</strong>):</p><p>[PHP]<?php namespace App\Http;</p><p></p><p>class FindRetros {</p><p> private $pageName, $callTimeout, $usingCloudFlare, $apiPath;</p><p></p><p> function __construct() {</p><p> $this->pageName = 'RevivalRP';</p><p> $this->requestTimeout = 2;</p><p> $this->usingCloudFlare = true;</p><p> $this->apiPath = 'https://findretros.com/';</p><p></p><p> if ($this->usingCloudFlare) {</p><p></p><p> if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))</p><p> $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];</p><p> else if (isset($_SERVER['HTTP_X_REAL_IP']))</p><p> $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];</p><p> else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))</p><p> $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];</p><p></p><p> }</p><p></p><p> }</p><p></p><p> public function hasClientVoted()</p><p> {</p><p> if (!$this->_isVoteCookieSet())</p><p> {</p><p> $urlRequest = $this->apiPath . 'validate.php?user=' . $this->pageName . '&ip=' . $_SERVER['REMOTE_ADDR'];</p><p> $dataRequest = $this->_makeCurlRequest($urlRequest);</p><p></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> }</p><p></p><p> return true;</p><p> }</p><p></p><p> public function redirectClientToVote()</p><p> {</p><p> header('Location: ' . $this->apiPath . 'servers/' . $this->pageName . '/vote?minimal=1');</p><p> exit();</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> curl_close($curl);</p><p> } else {</p><p></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></p><p> return $requestData;</p><p> }</p><p></p><p> private function _setVoteCookie()</p><p> {</p><p> $rankingsResetTime = $this->_getRankingsResetTime();</p><p> setcookie('voting_stamp', $rankingsResetTime, $rankingsResetTime);</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> }</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> date_default_timezone_set('America/Chicago');</p><p> $rankingsResetTime = mktime(0, 0, 0, date('n'), date('j') + 1);</p><p> date_default_timezone_set($serverDefaultTime);</p><p></p><p> return $rankingsResetTime;</p><p> }</p><p>}[/PHP]</p><p></p><p>3. Then call the file whereever you want, I called mine in one of the files in the <strong>App\Http\Middleware\Session</strong> folder.</p><p></p><p>Example (it will only be called in production environment):</p><p>[PHP]</p><p>if (App::environment('production', 'staging')) {</p><p> if (!$request->exists('novote')) {</p><p> $FindRetros = new App\Http\FindRetros();</p><p> </p><p> if (!$FindRetros->hasClientVoted()) {</p><p> $FindRetros->redirectClientToVote();</p><p> }</p><p> }</p><p>}</p><p>[/PHP]</p><p></p><p>Example of a full middleware file:</p><p>[CODE]<?php</p><p></p><p>namespace App\Http\Middleware\Session;</p><p></p><p>use Illuminate\Support\Facades\Auth;</p><p></p><p>use App;</p><p>use Closure;</p><p></p><p>class Guest</p><p>{</p><p> /**</p><p> * Handle an incoming request.</p><p> *</p><p> * @param \Illuminate\Http\Request $request</p><p> * @param \Closure $next</p><p> * @return mixed</p><p> */</p><p> public function handle($request, Closure $next)</p><p> {</p><p> if (Auth::check()) {</p><p> return redirect('/me');</p><p> }</p><p></p><p> if (App::environment('production', 'staging')) {</p><p> if (!$request->exists('novote')) {</p><p> $FindRetros = new App\Http\FindRetros();</p><p></p><p> if (!$FindRetros->hasClientVoted()) {</p><p> $FindRetros->redirectClientToVote();</p><p> }</p><p> }</p><p> }</p><p></p><p> return $next($request);</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>Then that's it, you have the FindRetros Voting Validator setup on your Laravel application!</p></blockquote><p></p>
[QUOTE="Jerry, post: 429851, member: 35321"] Hi, A few people have asked me to set this up for them since they were having issues implementing the voting validator to their Laravel application, so I'm going to release it here. I did not code it myself, all I did was make a new class and copy and pasted the code from [URL]https://github.com/FindRetros/Vote-Validator/[/URL]. Steps: 1. Make a new PHP file called [B]FindRetros.php[/B] in the App\Http folder. 2. Paste this code to the file ([B]replace 'pageName' with your FindRetros page name[/B]): [PHP]<?php namespace App\Http; class FindRetros { private $pageName, $callTimeout, $usingCloudFlare, $apiPath; function __construct() { $this->pageName = 'RevivalRP'; $this->requestTimeout = 2; $this->usingCloudFlare = true; $this->apiPath = 'https://findretros.com/'; if ($this->usingCloudFlare) { if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; else if (isset($_SERVER['HTTP_X_REAL_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP']; else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } } 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 . 'servers/' . $this->pageName . '/vote?minimal=1'); 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; } }[/PHP] 3. Then call the file whereever you want, I called mine in one of the files in the [B]App\Http\Middleware\Session[/B] folder. Example (it will only be called in production environment): [PHP] if (App::environment('production', 'staging')) { if (!$request->exists('novote')) { $FindRetros = new App\Http\FindRetros(); if (!$FindRetros->hasClientVoted()) { $FindRetros->redirectClientToVote(); } } } [/PHP] Example of a full middleware file: [CODE]<?php namespace App\Http\Middleware\Session; use Illuminate\Support\Facades\Auth; use App; use Closure; class Guest { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Auth::check()) { return redirect('/me'); } if (App::environment('production', 'staging')) { if (!$request->exists('novote')) { $FindRetros = new App\Http\FindRetros(); if (!$FindRetros->hasClientVoted()) { $FindRetros->redirectClientToVote(); } } } return $next($request); } } [/CODE] Then that's it, you have the FindRetros Voting Validator setup on your Laravel application! [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
CMS Releases
[Laravel] FindRetros Voting Validator
Top