...

View Full Version : This web page has a redirect loop | PHP redirect...



martynball
04-11-2012, 12:24 AM
Hey guys, any idea why Chrome is throwing this error at me?


This web page has a redirect loop


The website will not load as apparently there is a looping redirect... I don't see how that could be happening :S



<?php
session_start();
require "php/general.php";
require "pages/header.php";
$page = $_GET['page'];
//Reload page page if no URL variable is set
if ($page == "") {
header('Location: http://martynleeball.goodluckwith.us?page=main');
}

//Is the user logged in?
if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
//Make certain that the login page is loaded
header('Location: http://martynleeball.goodluckwith.us?page=login');

//User is not logged in, connect to database
include "php/connect.php";
}
?>
<title><?php echo $titles[$page] ?></title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script type="text/javascript">
<?php
include $js[$page];
?>
</script>
</head>
<body>
<?php
include $pages[$page];
?>
</body>
</html>

mlseim
04-11-2012, 12:37 AM
Start out by commenting-out the header lines, one at a time.
If the error goes away, you'll know which one is causing the loop.

What is happening is, you're executing a script, something tells it to go
somewhere else, and it gets back to where it started. It continues to loop
like that. Chrome may be the browser that detects it ... whereas the other
browsers might just "hang up" and you'll get "browser not responding"?

If it ends up being a header line, let us know.

Otherwise, start commenting-out the include lines one at a time until the error disappears.

You have to troubleshoot this on your own, because we can't run it ourselves.


.

tangoforce
04-11-2012, 12:41 AM
Assuming that the page/php code you've shown is also used for your login/general template then this will do it:


//If no session stuff set
if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
//Redirect to login... and again... and again.. and again..
header('Location: http://martynleeball.goodluckwith.us?page=login');


Bad idea to use a header for that.

Instead do this:


//If no session stuff set
if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
//change $page to login and continue
$page = 'login';

martynball
04-11-2012, 12:42 AM
It seems to be the following part:


//Is the user logged in?
if (!$_SESSION['user'] || $_SESSION['sid'] != session_id()) {
//Make certain that the login page is loaded
header('Location: http://martynleeball.goodluckwith.us?page=login');

//User is not logged in, connect to database
include "php/connect.php";
}


Edit: Oh crap yeah, tangoforce, I just noticed. I don't actually need to reload the page. I just need to redefine the variable before the rest of the page is loaded



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum