How to redirect to specific page if not logged in with .htaccess

前端 未结 5 845
没有蜡笔的小新
没有蜡笔的小新 2021-01-06 00:30

I am running apache2 and php5 in my windows PC.

I have protected my directory using .htaccess and.htpasswd. If login information is not set

5条回答
  •  鱼传尺愫
    2021-01-06 01:02

    You can use http authentication in PHP in addition to Apache (via .htaccess). This might give you more control.

    From the manual:

    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="My Realm"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Text to send if user hits Cancel button';
        exit;
    } else {
        // do the redirect here?
    }
    

提交回复
热议问题