Redirect Loop

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Hey
So I tried to implement voting to my hotel and I get ERR_TOO_MANY_REDIRECTS error. On top of client, I include vote.php and vote.php contains:
PHP:
<?php

require_once 'findretros_config.php';
require_once 'findretros.php';

$FindRetros = new FindRetros();

if($FindRetros->hasClientVoted()) {

    header('Location:/client');

}else{

    // echo 'You have yet to vote!';

    $FindRetros->redirectClientToVote();

}
findretros_config.php

PHP:
<?php
$_CONFIG = array(
    /* What is "username" of your page on FindRetros? */
   
    'pagename' => 'HablitHotel1',
    /* 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' => true,
    /* Incase FindRetros.com has a new domain, change it below. */
    'api' => 'https://findretros.com/'
);
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,933
try this in your forcevote.php

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=FINDRETRONAME&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=FINDRETROSNAME&api=http:!!HOTELURL!index?novote");
exit;
}
}
?>
Please don’t try that.
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
try this in your forcevote.php

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=FINDRETRONAME&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=FINDRETROSNAME&api=http:!!HOTELURL!index?novote");
exit;
}
}
?>
Didn't work :(
 

JynX

Posting Freak
Feb 6, 2016
710
438
Your issue is the fact that you're checking if they have voted and redirecting them to the client.
kHdyAbpGSeWPC9vC3Jwlnw.png

If they are on the client when this check is ran and they HAVE voted it will just endlessly redirect forever. Chrome stops this by throwing the error that you posted which stops the endless loop. This code is also not good considering they won't be able to access ANY other page than the client after they have voted.

Check Josh's vote validator on Github here:


In case you're lazy you can just use the following instead of the code you have..
PHP:
<?php

require_once 'findretros_config.php';
require_once 'findretros.php';

$FindRetros = new FindRetros();

if($FindRetros->hasClientVoted()) {

}else{
    $FindRetros->redirectClientToVote();
}
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Your issue is the fact that you're checking if they have voted and redirecting them to the client.
kHdyAbpGSeWPC9vC3Jwlnw.png

If they are on the client when this check is ran and they HAVE voted it will just endlessly redirect forever. Chrome stops this by throwing the error that you posted which stops the endless loop. This code is also not good considering they won't be able to access ANY other page than the client after they have voted.

Check Josh's vote validator on Github here:


In case you're lazy you can just use the following instead of the code you have..
PHP:
<?php

require_once 'findretros_config.php';
require_once 'findretros.php';

$FindRetros = new FindRetros();

if($FindRetros->hasClientVoted()) {

}else{
    $FindRetros->redirectClientToVote();
}
thanks, this worked!
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Your issue is the fact that you're checking if they have voted and redirecting them to the client.
kHdyAbpGSeWPC9vC3Jwlnw.png

If they are on the client when this check is ran and they HAVE voted it will just endlessly redirect forever. Chrome stops this by throwing the error that you posted which stops the endless loop. This code is also not good considering they won't be able to access ANY other page than the client after they have voted.

Check Josh's vote validator on Github here:


In case you're lazy you can just use the following instead of the code you have..
PHP:
<?php

require_once 'findretros_config.php';
require_once 'findretros.php';

$FindRetros = new FindRetros();

if($FindRetros->hasClientVoted()) {

}else{
    $FindRetros->redirectClientToVote();
}

PHP:
<?php

require_once('findretros_config.php');
require_once('findretros.php');

$findRetros = new FindRetros();

if (!$findRetros->hasClientVoted()) {
    $findRetros->redirectClientToVote();
}

You can simply do this, no need for an empty if statement.
 

JynX

Posting Freak
Feb 6, 2016
710
438
PHP:
<?php

require_once('findretros_config.php');
require_once('findretros.php');

$findRetros = new FindRetros();

if (!$findRetros->hasClientVoted()) {
    $findRetros->redirectClientToVote();
}

You can simply do this, no need for an empty if statement.
True, didn't really look @ the code more or less copied from the Git's example and removed the echo's. But yeah, use his.
 

Users who are viewing this thread

Top