il codice è il seguente :
<?php function login($strUsername, $strPassword ,$objJSession) {
$str_db_host = '#######';
$str_db_user = '#######';
$str_db_password = '#######';
$str_db_name = '#######';
$db = mysql_connect($str_db_host, $str_db_user, $str_db_password) or die ('Errore durante la connessione');
mysql_select_db($str_db_name, $db) or die ('Errore durante la selezione del db');
$sql = 'SELECT * FROM logintb WHERE username = "' . $strUsername . '" AND password = "'. $strPassword . '"';
$res = mysql_query($sql) or die (mysql_error());
if ($res){
while ($row = mysql_fetch_array($res)){
$objJSession->set("username", $strUsername, "condominio");
$objJSession->set("password", $strPassword, "condominio");
return true;
}
}
else
die ("errore sql");
}?>
Il controllo sulla homepage è questo :
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
$strLoginAddress = $params->get('loginAddress');
$objJSession = JSession::getInstance('none',array());
if ( $objJSession->get("username", null, "condominio") == null or $objJSession->get("password", null, "condominio") == null ) {
header("Location:" . $strLoginAddress);
}
?>