vicenrele
vicenrele

Reputation: 971

How can I forbid access to an URL in PHP?

If I have a URL called: www.example.com and I have an application in the next URL: www.example.com/app/, how can I forbid access to www.example.com but not to the app? Any simple way?

Thanks.

Upvotes: 0

Views: 92

Answers (2)

Boldewyn
Boldewyn

Reputation: 82814

If you need to do this from within PHP, you can simply set the correct HTTP status and exit the program:

if ($_SERVER['PATH_INFO'] === '/') {
    header('', false, 403);
    die('Access forbidden.');
}

See the header() docs and the description of HTTP return codes.

But in the general case, @CooPer and the others are right, the server config is a better location to handle that globally.

Upvotes: 1

Ali Akbar Azizi
Ali Akbar Azizi

Reputation: 3516

use .htaccess

Order Deny,Allow
Deny from all
Allow from 127.0.0.1

<Directory /app>
    Order Allow,Deny
    Allow from all
</Directory>

Upvotes: 2

Related Questions