Looking at your code I have got these questions:
- What is the purpose of verification2.php script?
- What is the user identifier you want to use for user redirection?
I would do only one script for adding user and one script for login. The following is an example flow for login:
- check if form was submited
- if yes, check for the user data in the database
- if match is found redirect to a user area (a page for authenticated users)
- if match is not found display an error message and the form with username already filled-in
The code would be something like:
<?php
// begin session on the very beginning of the script
session_start();
// initialize the username variable for filling in the form after incorrect login
$username = '';
// initialize the array for storing error messages
$messages = array();
// check if form was submitted and if yes, do all the stuff
if(isset($_POST['submit'])) {
$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
// no need to filter password since you will hash it
// actually by filtering it you might unvalidate it
// hash the password (hashing is not the same as encrypting)
$password = sha1( $_POST['password'] );
/*** connect to database ***/
/*** mysql hostname ***/
$mysql_hostname = 'localhost';
/*** mysql username ***/
$mysql_username = 'root';
/*** mysql password ***/
$mysql_password = '';
/*** database name ***/
$mysql_dbname = 'ges_tache';
try
{
$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
/*** set the error mode to excptions ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** prepare …