Redirect Loop

Berk

c00l c4n u g1mme ur c0d3 plox
Developer
Messages
749
Likes
131
#1
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
Messages
3,584
Likes
3,588
#2
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

c00l c4n u g1mme ur c0d3 plox
Developer
Messages
749
Likes
131
#3
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

pathetic.site
Messages
712
Likes
437
#5
Your issue is the fact that you're checking if they have voted and redirecting them to the client.

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: [ To view this link you must register 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

c00l c4n u g1mme ur c0d3 plox
Developer
Messages
749
Likes
131
#6
Your issue is the fact that you're checking if they have voted and redirecting them to the client.

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: [ To view this link you must register 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!
 

Wess

BYPASSING OVERRIDE
Staff member
FindRetros Moderator
Messages
3,742
Likes
2,049
#7
Your issue is the fact that you're checking if they have voted and redirecting them to the client.

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: [ To view this link you must register 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

pathetic.site
Messages
712
Likes
437
#8
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 (Users: 0, Guests: 1)

Top