Asain
Asain

Reputation: 37

PHP redirect header is not redirecting?

I am using following code to redirect

header('Location: '.$fileID.'php');
}
else if (!isset($_SESSION['login']))
echo '<p>you need to register first.</p>' ;
?>

$fileID has a value bacuse I am using this value in other part of code and that works fine. I also tried

echo '<script>window.location="'.$fileID.'php"</script>';

but got a notfound error. I would like to get it working by any of these methods but would prefer the header method. Any help is appreciated.

Upvotes: 0

Views: 88

Answers (2)

Grim Reaper
Grim Reaper

Reputation: 561

I wanted to put this in a comment but I don't have enough reputation :( Anyways try changing your header from this:

header('Location: '.$fileID.'php');

To this:

header('Location: '.$fileID.'.php');

Upvotes: 1

Daniel W.
Daniel W.

Reputation: 32340

  1. You should exit; after redirect with headers, because the script will go on executing otherwise which can lead to unintended side effects.

  2. but got a notfound error.

URL seems wrong, echo the output and see if it matches your expected location.

Upvotes: 1

Related Questions