DevStarlight
DevStarlight

Reputation: 804

header redirect not working at all

I have a php file called init.php with which I want to load all my inc.php files (that contains all the html). This is the structure of my file.

define ("HTML", __DIR__ . '/page/');

$page = !empty($_GET['page']) ? $_GET['page'] : 'index';

if (!file_exists(HTML . $page . '.inc.php'))
    $page = 'index'; 

header('Location: ' . HTML  . $page . '.inc.php');

For any reason, my redirection doesn't redirect to any place where it should redirect (localhost/page/index.inc.php)

Any idea of what is happening there?

Note that i'm at index.php in my root directory and i've required_once init.php which is in the same root directory.

Upvotes: 0

Views: 58

Answers (1)

jonnu
jonnu

Reputation: 728

Location should be a URI, not a file path!

header('Location: /page/' . $page . '.inc.php');

__DIR__ will give you the directory of the file that is being parsed (for example, /home/site/index.php. The Location header is expecting a URI (for example, /page/something.php), not a file system path.

Upvotes: 2

Related Questions