Client stuck at 76% / Voting API too many re-directs [HelpRequest]

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
The problem is, some users are able to vote, connect normally, but others arent they are either stuck at 76% or they get this error as shown in the picture below this sentence.

Toomany.png


I know the voting API is causing this I'll post my voting script here could someone please assist me if there is anything wrong.
Things I've done;
forcevote.php is included in /client.php
FindRetros after voting is set to =

forcevote.php script is done like this;
If this code is wrong, could someone please write me a proper clean script so I can use in my forcevote.php all help is appreciated
PHP:
<?php
if(isset($_GET['voted'])) {
}
else {
$userip = "{$_SERVER['REMOTE_ADDR']}";
$current_url = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
$url = 'http://votingapi.com/validate.php?user=robbo&ip=' . $userip;
$context = stream_context_create(array('http' => array('timeout' => 1)));
$data = @file_get_contents($url, 1, $context);
if(!$data || !is_numeric($data)) {
return "Error";
}
else if ($data == 1 || $data == 2) {
}
else {
header ("Location: http://votingapi.com/vote.php?username=robbo&api=http:!!robbo.pw!index?novote");
exit;
}
}
?>

I have posted a smiliar problem like this previously please don't get confused, the issue was not resolved.
And please read every thing I've wrote in detail so that you are aware of the problem.. all help/support is kindly appreciated.


Please also do not hesitate to ask me for any information about this problem, anything that I havent included.
 

Joe

Well-Known Member
Jun 10, 2012
4,158
1,943
Try using the official API released by FindRetro's by clicking . I sometimes get this error too, it's weird, comes and goes.
 

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
Try using the official API released by FindRetro's by clicking . I sometimes get this error too, it's weird, comes and goes.
Okay Im using the one you've linked me, but it says it;s voted and it redirecting me to robbo.pw/client?voted as I set it to but, votes dont go through..
 
where did u put your force vote at on client.php? maybe that has to do with it?
top, includes
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
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;
    }
}
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();
}
?>
You should really read their documentation bro, your script is wayyy outdated compared to this one.
 
Last edited:

CosmoPeak

PeakRP.com
May 15, 2016
271
268
PHP:
Call the voting here as an external page.
PHP:
You should really read their documentation bro, your script is wayyy outdated compared to this one.
It really doesn't make a difference, this issue is unrelated to the script. Using $_GET['redirect'] is just a workaround to the problem. The actual issue is the IP for the user on the hotel's web server and FindRetro's web server do not match. One thing I've noticed is FindRetros supports IPv6 (not sure if it's recent, but I think it may be), so all servers will need to support IPv6 as well. However, there have been times when both IPs seemingly match and I still get the redirect issue, so I'm not sure exactly how the FindRetros API checks if someone has voted or not.

(Edit) Seems this link no longer works: , so it's difficult to test/figure out what is wrong.

@bigdawg
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
It really doesn't make a difference, this issue is unrelated to the script. Using $_GET['redirect'] is just a workaround to the problem. The actual issue is the IP for the user on the hotel's web server and FindRetro's web server do not match. One thing I've noticed is FindRetros supports IPv6 (not sure if it's recent, but I think it may be), so all servers will need to support IPv6 as well. However, there have been times when both IPs seemingly match and I still get the redirect issue, so I'm not sure exactly how the FindRetros API checks if someone has voted or not.



@bigdawg
You don't seem to have looked at the coding before you decided to answer. $_GET['redirect'] is something I use, if the user logs in, and I either want him to be redirected directly to client or me page.
I've fixed the IP problem, since it gets validated by the script itself and not the FindRetros system.
Next time, bother to read before you reply an irrelevant comment.

If this didn't work, I wouldn't have used it myself.
 

CosmoPeak

PeakRP.com
May 15, 2016
271
268
You don't seem to have looked at the coding before you decided to answer. $_GET['redirect'] is something I use, if the user logs in, and I either want him to be redirected directly to client or me page.
I've fixed the IP problem, since it gets validated by the script itself and not the FindRetros system.
Next time, bother to read before you reply an irrelevant comment.
Ah, my bad. I often see people redirecting to ?voted. Your script is just a copy of the official FindRetros script. It doesn't "validate" or make any extra checks, the issue is the difference between IP addresses between the FindRetros website and the hotel's web server. The script still needs to contact the FindRetros API, it doesn't magically know if the user has voted or not.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Ah, my bad. I often see people redirecting to ?voted. Your script is just a copy of the official FindRetros script. It doesn't "validate" or make any extra checks, the issue is the difference between IP addresses between the FindRetros website and the hotel's web server. The script still needs to contact the FindRetros API, it doesn't magically know if the user has voted or not.
PHP:
 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;
    }
Magical fix, if you bothered to read or understand coding.
 

CosmoPeak

PeakRP.com
May 15, 2016
271
268
PHP:
 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;
    }
Magical fix, if you bothered to read or understand coding.
Again, this won't fix Sly's issue at all. The issue isn't the code, it's the web server being configured differently to that used for FindRetros.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Again, this won't fix Sly's issue at all. The issue isn't the code, it's the web server being configured differently to that used for FindRetros.
I realized long time ago, that it's FindRetros own mistake due to their bad coding skills, but yet this fixed the issue for me.
 

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
I just use this and seems to work fine for me
Code:
<?php
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
$url = 'http://votingapi.com/validate.php?user=George&ip=' . $ip;
$hasvoted = @file_get_contents($url);
if($hasvoted != '1' && $hasvoted != '2'){
 header ("Location: https://findretros.com/vote/George");
 exit;
}
?>
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
I just use this and seems to work fine for me
Code:
<?php
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
$url = 'http://votingapi.com/validate.php?user=George&ip=' . $ip;
$hasvoted = @file_get_contents($url);
if($hasvoted != '1' && $hasvoted != '2'){
 header ("Location: https://findretros.com/vote/George");
 exit;
}
?>
Same here, works fine for me.

Sent from my SM-G928F using Tapatalk
 

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
had a friend who had that redirect error but afterr switching to that I havent heard her mention it at all and its been about 2 weeks
 

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
Guys thankyou all for your support right now I've changed my script to a simpler one.
I believe this seems to be working fine?
PHP:
<?php



    $ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
    $res = file_get_contents("http://votingapi.com/validate.php?user=robbo&ip=".$ip);
    if($res != 1 && $res != 2){
        header("Location: https://findretros.com/rankings/vote/Robbo");
    }


?>
 

Users who are viewing this thread

Top