# Php user reg /login system

**URL:** <https://forum.kirupa.com/t/php-user-reg-login-system/187159>\
**Category:** Uncategorized\
**Created:** [April 27, 2006, 2:50am UTC](https://forum.kirupa.com/t/php-user-reg-login-system/187159 "2006-04-27T02:50:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdl](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jdl](https://forum.kirupa.com/u/jdl)\
**Post date:** [April 27, 2006, 2:50am UTC](https://forum.kirupa.com/t/php-user-reg-login-system/187159/1 "2006-04-27T02:50:16Z")

</div>

Hi,

I’m been trying to implement the following tutorial:

[http://www.olate.co.uk/articles/185](http://www.olate.co.uk/articles/185)

But I don’t understand where you put the init file in each page.

He says:

> The next part just inserts the data into the database. You may notice that we don’t have a mysql\_connect() function anywhere. This is because I will leave it up to a initialisation file which will be included on every page. An example file would look like the following:

EG the register form is:

```php

<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
     // Show the form
     include 'register_form.inc.php';
     exit;
}
else
{
     // Check if any of the fields are missing
     if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass']))
     {
          // Reshow the form with an error
          $reg_error = 'One or more fields missing';
          include 'register_form.inc.php';
          exit;
     }

     // Check if the passwords match
     if ($_POST['password'] != $_POST['confirmpass'])
     {
          // Reshow the form with an error
          $reg_error = 'Your passwords do not match';
          include 'register_form.inc.php';
          exit;
     }
     // Everything is ok, register
     user_register ($_POST['username'], $_POST['password']);

     echo 'Thank you for registering on our site, <a href="index.php">click here</a> to go back.';
}
?>

```

So do you go:

```php

<?php
// Start the session
session_start();
// MySQL Settings
$db_host = 'localhost';
$db_user = 'matt';
$db_pass = '1234';
$db_database = 'user_auth';
// Connect to the database
mysql_connect ($db_host, $db_user, $db_pass) or die ('Could not connect to the database.');
mysql_selectdb ($db_database) or die ('Could not select database.');
// Seed the random number generator
srand();
// Include functions
include 'functions.php';
?>
<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
     // Show the form
     include 'register_form.inc.php';
     exit;
}
else
{
     // Check if any of the fields are missing
     if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass']))
     {
          // Reshow the form with an error
          $reg_error = 'One or more fields missing';
          include 'register_form.inc.php';
          exit;
     }

     // Check if the passwords match
     if ($_POST['password'] != $_POST['confirmpass'])
     {
          // Reshow the form with an error
          $reg_error = 'Your passwords do not match';
          include 'register_form.inc.php';
          exit;
     }
     // Everything is ok, register
     user_register ($_POST['username'], $_POST['password']);

     echo 'Thank you for registering on our site, <a href="index.php">click here</a> to go back.';
}
?>

```

I can’t get the links or I guess syntax right (my usual problem!)

Help appreciated , Thanks
