Page 1 of 1

Redirect loop ?

Posted: Fri Dec 03, 2010 5:44 am
by zaster79
I have a page called 1.php with the following code, it is the first code on the page no other code is executed before this.

It is supposed to check if a session variable is not set. If not, it redirects the user to the start of the process. That way if the users favorite or bookmark any page within the process, they will always find themselves at the start.

1.php

Code: Select all

<?php
session_start();
if (!$_SESSION['session_company']){
header('Location: http://mydomain.com/app/test/index.php');
}
?>
However....

If i go directly to 1.php, the redirect starts waits a few seconds and then this is displayed in my browser...

"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

The re-direct will not work in IE either.

Any ideas anyone? Please...

Re: Redirect loop ?

Posted: Fri Dec 03, 2010 7:20 am
by curlybracket

Re: Redirect loop ?

Posted: Fri Dec 03, 2010 7:56 am
by zaster79
Thanks

index.php

Code: Select all

<?php
session_start();
$_SESSION['session_company'] =  "A Company Name";

if (isset($_GET['username'])) {
$_SESSION['session_username'] = $_GET['username'];

if ($_SESSION['session_username'] == ""){
$error = "<font color = red>* Please complete this field</font>";
}
if ($_SESSION['session_username'] != ""){
header('Location: http://www.mydomain.com/app/0.php');
}
}
?>
In the index.php html, there is a form that submits to index.php.

Re: Redirect loop ?

Posted: Sat Dec 04, 2010 8:36 am
by curlybracket
My guess is that $_SESSION['session_username'] is not empty and index.php is redirecting you to 0.php. And my second guess is that you have another redirect in 0.php. Try to change this code:

Code: Select all

if ($_SESSION['session_username'] != ""){
  header('Location: http://www.mydomain.com/app/0.php');
}
to

Code: Select all

if ($_SESSION['session_username'] != ""){
  echo "redirect";
  //header('Location: http://www.mydomain.com/app/0.php');
}
and you will know.