<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 by GREGORY LE BRAS
// ----------------------------------------------------------------------
// LICENSE
//
// This file is part of ODCNMS - Open DataCenter Network Management System
//
// ODCNMS is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// ----------------------------------------------------------------------
// Original Author of file: GREGORY LE BRAS - http://www.odcnms.org/
// ----------------------------------------------------------------------
// User Authentication Function
function user_authentication ($username,$name_table_users,$mysql_hostname,$mysql_username,$mysql_password,$mysql_database)
{
$db_connect=mysql_connect($mysql_hostname,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$db_connect);
$username=trim(htmlentities($username));
$request=mysql_query("SELECT count(*) FROM $name_table_users WHERE username=\"$username\"") or die ("ERROR!");
$data = mysql_fetch_array($request);
if ($data[0] == 1) {
$_SESSION['user_authentication'] = "ok";
}
elseif ($data[0] == 0) {
session_start();
$_SESSION = array();
session_destroy();
header("Location:index.php?status=forbidden");
}
else {
header("Location:index.php?status=failed");
}
}
?>