Site.eu

Website builder questions

Protecting a page with a password

Welcome to the Site.eu Customer Forum!
Digivrienden.be
23 Aug 2025, 16:17

Protecting a page with a password

I'm making a website for an association and want to protect a page with a password

I've already tried it with a <> script but I can't get it to work.

Does anyone have experience with that, I can manage a little with HTML and PHP

Automatically translated
Site.nl
26 Aug 2025, 08:00

Good morning

If you want to do this via PHP and HTML.

File: protect.php

```

<?php

// Kies je gebruikersnaam en zet het wachtwoord als hash

$USER = 'admin';

$PASS_HASH = '$2y$10$qyUz1m8iQ8ezu4J8bI4KpOQ7Ff0hWJvE5lM7w8gS7a2iA3m4n5o6a'; // voorbeeldhash

// TIP: maak je eigen hash (voer dit 1x uit ergens): echo passwordhash('jouwSterkWachtwoord', PASSWORDDEFAULT);

function auth_fail() {

header('WWW-Authenticate: Basic realm="Beveiligd"');

header('HTTP/1.0 401 Unauthorized');

echo 'Authenticatie vereist.';

exit;

}

if (!isset($SERVER['PHPAUTHUSER'], $SERVER['PHPAUTHPW'])) {

auth_fail();

}

if ($SERVER['PHPAUTHUSER'] !== $USER || !passwordverify($SERVER['PHPAUTHPW'], $PASSHASH)) {

auth_fail();

}

// Vanaf hier is de gebruiker geauthenticeerd.

```

Use in a page:

```

<?php require DIR . '/protect.php'; ?>

<h1>Geheime inhoud</h1>

```

Automatically translated
Digivrienden.be
1 Sep 2025, 09:45

Thanks, I can definitely work with this

Automatically translated