Let say i've the follow files [index.php / admin.php / access.php]

**1) File index.php is with login form**

```
<form method="post" name="login" id="login" action="check.php">
Username : <input name="loginid" id="loginid" type="text">
Password : <input name="password" id="password" type="password">
</form>

```

it should send entries (user,pass) to file check.php so that check if the username and password is correct or not and i'd like to use this way

**2) File check.php** 

At file check.php it should do the following function
- Check if the user,pass is correct
- If correct then create cookies or somehow
- If wrong or empty send me back to login.php

Let say here are my db informations

```
$sql= "select * from settings where admuser='$loginid' and admpass='$password'";
$result = mysql_query($sql) or die("query failed: $sql");

```

**3) File access.php**

This file should compare if i've logged or not so that if not send me back to login.php

**4) File admin.php** [ needs access.php to check if i'm logged or not]

```
<?php
include('access.php');
echo "balah blah blah";
?>

```

So can anyone please write this example as simple as possible

That example will helps me a lot to study it as study case
cause i've tried before but failed so i really do not know why and here was my last question [Login not working after php updated](https://stackoverflow.com/questions/9025961/login-not-working-after-php-updated) but i found i need complate study case code that working.

thank you for helping