<?Php
ob_start();
session_start();
include "config/config.php"; 
$member_user_id=$_REQUEST['user_name'];
$password=$_REQUEST['password'];
$member_user_id=clean($member_user_id);
$member_user_id=RemoveSpecialChar($member_user_id);
$password=RemoveSpecialChar($password);

if(strlen($member_user_id)==10)
{
    $str="Select * from  tbl_memberreg where member_user_id='$member_user_id' ";
    $result=mysqli_query($connection,$str); 
    if(mysqli_num_rows($result)>0)
    {
        $row=mysqli_fetch_array($result);
        if($member_user_id==$row['member_user_id'] && $password==$row['password'] && $row['is_customer']==0 )
        {
        	$_SESSION['member_id']=$row['member_id'];
        	$_SESSION['member_user_id']=$row['member_user_id'];
        	$_SESSION['member_name']=$row['member_name'];
        	header("location:dashboard.php");
        }
        else
        {
            $msg='Wrong User or Password';
    	    header("location:login.php?msg=$msg");
    	    exit();
        }
    }
    else
    {
        $msg='Wrong User or Password';
    	    header("location:login.php?msg=$msg");
    	    exit();
    }
}
else
{
    	$msg='Wrong User or Password';
	    header("location:login.php?msg=$msg");
	    exit();
}

function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
function RemoveSpecialChar($str){ 
      
    // Using str_ireplace() function  
    $res = str_ireplace( array( '\'','-', '"', 
    ',' , ';', '<', '>',']' ,'['), ' ', $str); 
      
    // returning the result  
    return $res; 
    }
?>
