# Simple PHP Login not working in Kirby 3?

**URL:** <https://forum.getkirby.com/t/simple-php-login-not-working-in-kirby-3/22879>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 14, 2021, 11:13am UTC](https://forum.getkirby.com/t/simple-php-login-not-working-in-kirby-3/22879 "2021-07-14T11:13:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![urbanedge](https://avatars.discourse-cdn.com/v4/letter/u/cab0a1/32.png) [@urbanedge](https://forum.getkirby.com/u/urbanedge)\
**Post date:** [July 14, 2021, 11:13am UTC](https://forum.getkirby.com/t/simple-php-login-not-working-in-kirby-3/22879/1 "2021-07-14T11:13:08Z")

</div>

I’m converting a site over to Kirby 3, the site uses a basic PHP login with 1 username and password.

(u: test p: test).

```
session_start();

$userinfo = array(
    'test'=>'098f6bcd4621d373cade4e832627b4f6'
);

$msg = "";

if(isset($_POST['username'])) {

    if($userinfo[$_POST['username']] === md5($_POST['password'])) {
        $_SESSION['username'] = true;
    }
    else {
        $msg = "<h3>SORRY, YOUR USERNAME OR PASSWORD ARE INCORRECT.</h3>";
    }
}

```

When the user enters the correctly password they are logged in and can see additional navigation, this is all working fine.

The **problem** I’m having is, if a user enters the wrong username or password. On the non-Kirby site the $msg is echoed under the form, but for some reason on the Kirby site it is bringing up the debug mode and showing the error “ **Undefined index** ” instead of showing the $msg???

```
Whoops\Exception\ErrorException 

 if($userinfo[$_POST['username']] === md5($_POST['password'])) {

```

The PHP is in the head snippet and the form is on the footer snippet.

If I switch debug mode off the site then goes to a broken page “_This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible._”

Any help would be great.

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [July 14, 2021, 11:46am UTC](https://forum.getkirby.com/t/simple-php-login-not-working-in-kirby-3/22879/2 "2021-07-14T11:46:01Z")

</div>

> [@urbanedge](#):
>
> `$userinfo[$_POST['username']]`

If the user enters a wrong username, `$userinfo[$_POST['username']]` does not exists, hence you need to check if the key exists in the array:

```auto
 if($userinfo[$_POST['username']] ?? '' === md5($_POST['password'])) {

```

Here is how to restrict access in Kirby: [Restricting access to your site | Kirby CMS](https://getkirby.com/docs/cookbook/security/access-restriction)

---

<div class="post-metadata">

**Author:** ![urbanedge](https://avatars.discourse-cdn.com/v4/letter/u/cab0a1/32.png) [@urbanedge](https://forum.getkirby.com/u/urbanedge)\
**Post date:** [July 14, 2021, 1:26pm UTC](https://forum.getkirby.com/t/simple-php-login-not-working-in-kirby-3/22879/3 "2021-07-14T13:26:41Z")

</div>

Thank you very much!
