• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Too many redirects!

Archez

'
Senator
Joined
Jun 26, 2008
Messages
6,589
Solutions
1
Reaction score
70
Location
Mexico
I am having troubles solving this:

PHP:
if(!isset($_REQUEST['read']))
{
	header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}

if(isset($_REQUEST['read']) && !file_exists(PATH . '/system/pages/' . strtolower($_REQUEST['read']) . '.php'))
{
	header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}

If you know the basics of PHP you should know what I am doing.

# PATH is defined and is not causing it.
 
In which file is this placed in? index.php?

Edit;
try:


PHP:
if(isset($_REQUEST['read']) && !is_file(PATH . '/system/pages/' . strtolower($_REQUEST['read']) . '.php'))
{
    header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}else{
	header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}


If this check is done in the file you're redirecting to then you'll end up in a infinite loop.
 
Yes, it is part of my index.php. I just want the script to check if file.php ($_REQUEST['read'].php) exists, if it doesn't, it must redirect the user to the default file.php. In this case, $config['website']['index'] is "news", and news.php does exist in /system/pages/.

I tested your script btw, doesn't work either. >.<

Edit:
Solved.

I was not supposed to use a trailing slash at the beginning of file_exists().
 
Last edited:
PATH is a webpath, right? you can't be using that if you're gonna check if a file exists on the server side.

This should work:
PHP:
if(isset($_REQUEST['read']))
{
    $file = 'system/pages/' . strtolower($_REQUEST['read']) . '.php';

    if(is_file($file)){
        require($file);
    }else{
        header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
    }
}else{
    header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}

Edit;
Oh, really?
so what was PATH defined as?
I'm really curious because it seems you made magic happen if that was the only fix you did.
 
Last edited:
PATH is a webpath, right? you can't be using that if you're gonna check if a file exists on the server side.

This should work:
PHP:
if(isset($_REQUEST['read']))
{
    $file = 'system/pages/' . strtolower($_REQUEST['read']) . '.php';

    if(is_file($file)){
        require($file);
    }else{
        header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
    }
}else{
    header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}

Edit;
Oh, really?
so what was PATH defined as?
I'm really curious becayse it seems you made magic happen if that was the only fix you did.

I just removed PATH, I don't know why this affects file_exists(). PATH is defined as "/web", I am still using it for header().
 
I just removed PATH, I don't know why this affects file_exists(). PATH is defined as "/web", I am still using it for header().

lol "I was not supposed to use a trailing slash at the beginning of file_exists(). "
Then you did more than to remove the trailing slash. Nvm then.
 
PATH is a webpath, right? you can't be using that if you're gonna check if a file exists on the server side.

This should work:
PHP:
if(isset($_REQUEST['read']))
{
    $file = 'system/pages/' . strtolower($_REQUEST['read']) . '.php';

    if(is_file($file)){
        require($file);
    }else{
        header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
    }
}else{
    header('Location: ' .PATH . '/index.php?read=' . $config['website']['index']);
}

Edit;
Oh, really?
so what was PATH defined as?
I'm really curious because it seems you made magic happen if that was the only fix you did.
I know the problem is solved but I just wanted to say that the code Zisly posted is not secure... and ye, I know it was just an example but still.
 
Last edited:
Back
Top