Tools class

class Tools
{
public function escape($str) {
$str = get_magic_quotes_gpc()?stripslashes($str):$str;
$str = mysql_real_escape_string($str);
return $str;
}

public function redirect($str,$msg_no=NULL,$var=NULL) {
$str =$str.'.php';

if($msg_no):$msg = '?msg='.self::escape($msg_no);
else:$msg='';
endif;

if($var):$var=self::escape($var);
else:$var='';
endif;

header('location:'.$str.$msg.$var);
return true;
}

public function setSession($variable,$value)
{
$_SESSION[$variable] = $value;
}

public function unsetSession($variable)
{
session_unregister($variable);
}

public function authenticate($array)
{
$session = $_SESSION['user'];
$auth = false;
if(isset($session))
{
foreach($array as $arr)
{
if($arr==$_SESSION['user']['group'])
{
$auth = true;
}
}

if(!$auth)
{
self::redirect('notauthorized');
exit;
}
}else{
self::redirect('notauthorized');
exit;
}
}
}

?>

No comments:

Post a Comment