我正在寻找可以在新的Web项目中使用的框架.
我主要关心的是处理用户,因此我一直在寻找可以为我处理用户的框架.我使用PHP开发,因此最好是它应该使用的语言.
我希望该框架能够照顾到新用户注册,并且希望它能够处理会话和身份验证过程.
我有哪些选择,人们会推荐什么?
解决方法:
如果您唯一想做的是用户管理,则可以使用某些库(类)而不是完整的框架,因为(据我所知)没有任何东西可以称为仅用于用户管理的框架.
我现在正在制作一个名为aiki的框架,它是gpl,所以这是我为用户管理编写的类,它可能会对您有所帮助
<?php
class membership
{
var $permissions;
var $full_name;
var $username;
var $group_level;
function membership(){
session_start();
}
function login ($username, $password){
global $db, $layout;
$password = stripslashes($password);
$password = md5(md5($password));
$get_user = $db->get_row("SELECT * FROM aiki_users where username='".$username."' and password='".$password."' limit 1");
if($get_user->username == $username and $get_user->password == $password){
$host_name = $_SERVER['HTTP_HOST'];
$user_ip = $this->get_ip();
$usersession = $this->generate_session(100);
$_SESSION['aiki'] = $usersession;
$insert_session = $db->query("INSERT INTO aiki_users_sessions (`session_id`,`user_id`,`user_name`,`session_date`,`user_session`, `user_ip`) VALUES ('','$get_user->userid','$username',NOW(),'$usersession','$user_ip')");
$update_acces = $db->query("UPDATE `aiki_users` SET `last_login`= NOW(),`last_ip`='$user_ip', `logins_number`=`logins_number`+1 WHERE `userid`='$get_user->userid' LIMIT 1");
} else{
}
}
function isUserLogged ($userid){
global $db;
$user_session = $db->get_var("SELECT user_id FROM aiki_users_sessions where user_session='$_SESSION[aiki]'");
if ($user_session == $userid){
return true;
}else{
return false;
}
}
function getUserPermissions ($user){
global $db;
$user = mysql_escape_string($user);
$user = $db->get_row("SELECT userid, usergroup, full_name, username FROM aiki_users where username='$user'");
if ($user->userid and $this->isUserLogged($user->userid)){
$group_permissions = $db->get_row("SELECT group_permissions, group_level FROM aiki_users_groups where id='$user->usergroup'");
$this->full_name = $user->full_name;
$this->username = $user->username;
$this->group_level= $group_permissions->group_level;
}else{
$this->permissions = "";
}
$this->permissions = $group_permissions->group_permissions;
}
//function from Membership V1.0
//http://AwesomePHP.com/gpl.txt
function get_ip(){
$ipParts = explode(".", $_SERVER['REMOTE_ADDR']);
if ($ipParts[0] == "165" && $ipParts[1] == "21") {
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("REMOTE_ADDR")) {
$ip = getenv("REMOTE_ADDR");
}
} else {
return $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
//Generate session
function generate_session($strlen){
return substr(md5(uniqid(rand(),true)),1,$strlen);
}
function LogOut(){
global $db, $layout;
$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['SCRIPT_NAME'];
$queryString = $_SERVER['QUERY_STRING'];
$thisurlnologout = "http://" . $domain . $path . "?" . $queryString;
$thisurlnologout = str_replace("&operators=logout", "", $thisurlnologout);
$make_offline = $db->query("UPDATE `aiki_guests` SET `is_online`='0' WHERE `guest_session`='$_SESSION[aiki]' LIMIT 1");
$delete_session_data = $db->query("DELETE FROM aiki_users_sessions where user_session='$_SESSION[aiki]'");
unset($_SESSION['aiki']);
session_destroy();
session_unset();
$layout->html_output .= '<META HTTP-EQUIV="refresh" content="1;URL=http://'.$domain.$path.'"><center><b>Logging out</b></center>';
//die();
}
}
?>
这是一个简单的SQL转储
CREATE TABLE IF NOT EXISTS `aiki_guests` (
`userid` int(9) unsigned NOT NULL auto_increment,
`first_login` datetime NOT NULL,
`last_hit` datetime NOT NULL,
`last_hit_unix` int(11) NOT NULL,
`ip` varchar(40) NOT NULL,
`last_ip` varchar(40) NOT NULL,
`username` varchar(255) NOT NULL,
`guest_session` varchar(255) NOT NULL,
`hits` int(11) NOT NULL,
`is_online` int(11) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=54 ;
-- --------------------------------------------------------
--
-- Table structure for table `aiki_users`
--
CREATE TABLE IF NOT EXISTS `aiki_users` (
`userid` int(9) unsigned NOT NULL auto_increment,
`username` varchar(100) NOT NULL default '',
`full_name` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`sex` varchar(25) NOT NULL,
`job` varchar(255) NOT NULL,
`password` varchar(100) NOT NULL default '',
`usergroup` int(10) NOT NULL default '0',
`email` varchar(100) NOT NULL default '',
`avatar` varchar(255) NOT NULL,
`homepage` varchar(100) NOT NULL default '',
`first_ip` varchar(40) NOT NULL default '0',
`first_login` datetime NOT NULL,
`last_login` datetime NOT NULL,
`last_ip` varchar(40) NOT NULL,
`user_permissions` text NOT NULL,
`maillist` int(1) NOT NULL,
`logins_number` int(11) NOT NULL,
`randkey` varchar(255) NOT NULL,
`is_active` int(5) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
--
-- Table structure for table `aiki_users_groups`
--
CREATE TABLE IF NOT EXISTS `aiki_users_groups` (
`id` int(3) NOT NULL auto_increment,
`app_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`group_permissions` varchar(255) NOT NULL,
`group_level` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
-- --------------------------------------------------------
--
-- Table structure for table `aiki_users_sessions`
--
CREATE TABLE IF NOT EXISTS `aiki_users_sessions` (
`session_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`user_name` varchar(255) NOT NULL,
`session_date` datetime NOT NULL,
`user_session` varchar(255) NOT NULL,
`user_ip` varchar(100) NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
现在您所需要做的就是添加数据库并在其中创建用户
请记住,您将必须两次输入md5密码,例如:
$password = "what ever";
$password = md5(md5($password));
并使用此类:
然后建立一个表格
$membership =新的membership();
登录:
$membership-> login($_ POST [‘username’],$_POST [‘password’]);
然后您可以在groups表中建立组
$membership-> getUserPermissions($username);
那么您可以根据返回的$membership-> permissions值执行操作
喜欢 :
切换($membership->权限){
}