oshirowanen
oshirowanen

Reputation: 15925

php header location issues

Anyone know why this is happening?

In my code I have the following line this I think is causing problems:

header('Location: /var/www/index.php');

but it keeps giving me the following error:

[Thu Jul 28 22:15:18 2011] [error] [client 127.0.0.1] script '/var/www/account/index.php' not found or unable to stat, referer: http://localhost

The possible problem line:

header('Location: /var/www/index.php');

is in a file located at:

/var/www/account/oauth/openid/check.php

Upvotes: 0

Views: 1962

Answers (3)

Martin Tournoij
Martin Tournoij

Reputation: 27822

You are directing the browser to an absolute path. This is wrong, you need to use a path relative to the document root. The browser can't see anything outside of the document root.

In your case

header('Location: /var/www/index.php');

Should probably be:

header('Location: /index.php');

Since /var/www/ is your document root.

Upvotes: 5

barfoon
barfoon

Reputation: 28157

A URL must be specified in the header() call, you are using a path. Try using the relative location to index.php.

From the PHP documenation:

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.

Upvotes: 1

Paul
Paul

Reputation: 141829

That will send the browser to: /var/www/index.php when you probably just want to send them to index.php.

You should use absolute urls with location headers anyways so something like:

header('Location: http://mydomain.com/index.php');

Upvotes: 3

Related Questions