Redirect loop ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zaster79
Forum Newbie
Posts: 7
Joined: Tue Nov 16, 2010 9:37 am

Redirect loop ?

Post 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...
curlybracket
Forum Commoner
Posts: 59
Joined: Mon Nov 29, 2010 2:40 pm

Re: Redirect loop ?

Post by curlybracket »

zaster79
Forum Newbie
Posts: 7
Joined: Tue Nov 16, 2010 9:37 am

Re: Redirect loop ?

Post 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.
curlybracket
Forum Commoner
Posts: 59
Joined: Mon Nov 29, 2010 2:40 pm

Re: Redirect loop ?

Post 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.
Post Reply