管理用户的框架

发布于 2024-07-26 08:58:49 字数 179 浏览 6 评论 0原文

我正在寻找一个可以在我的新网络项目中使用的框架。

我主要关心的是处理我的用户,因此我正在寻找一个可以为我处理他们的框架。 我使用 PHP 进行开发,所以最好是它应该使用的语言。
我希望该框架能够处理新用户的注册,并且我还希望它能够处理会话和身份验证过程。

我有哪些选择,人们有什么建议?

I'm looking for a framework I can use in my new webproject.

The main concern for me is handling my users, therefore I'm on the lookout for a framwork that can handle them for me. I develop in PHP, so preferably that's the language it should use.
I would like the framework to take care of new users signing up and I would also like it to handle the sessions and authentication process.

What kind of options do I have, and what do people recommend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一袭白衣梦中忆 2024-08-02 08:58:49

如果您唯一想做的就是用户管理,那么您可以使用一些库(类)而不是完整的框架,因为(据我所知)没有任何东西称为仅用于用户管理的框架。
我现在正在制作一个名为 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 = newmembership();

登录:
$membership->login($_POST['用户名'], $_POST['密码']);

您可以在组表中构建组,然后

$membership->getUserPermissions($username);

然后您可以根据返回的 $membership->permissions 值执行操作
就像:

switch ($membership->permissions){

}

if the only thing you want to do is user management then you may use some libraries ( classes ) instead of full framework, because there is nothing ( as far as I know ) called framework for user management only..
I'm working now to make a framework called aiki, and it's gpl, so here is the class I wrote for user management it may help you

<?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();
        }

    }
?>

and here is a simple sql dump for that

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 ;

now all you need is to add the db and create users inside it
remember that you will have to md5 the password twice, like:

$password = "what ever";
$password = md5(md5($password));

and to use this class:
build a form then

$membership = new membership();

Login:
$membership->login($_POST['username'], $_POST['password']);

and you can build groups inside the groups table then

$membership->getUserPermissions($username);

then you can do thing based on the returned $membership->permissions value
like :

switch ($membership->permissions){

}

反目相谮 2024-08-02 08:58:49

如果您不需要完整的 CMS,Zend Framework 非常适合直接使用成分。

您可能对 Zend_Acl、Zend_Auth 和 Zend_Session 组件最感兴趣。

我希望这就是您正在寻找的。

If you don't want a full CMS, the Zend Framework is excellent for drop-in components.

You would be most interested in the Zend_Acl, Zend_Auth, and Zend_Session components.

I hope this is what you're looking for.

痴者 2024-08-02 08:58:49

这是一个您可以使用 Drupal 的项目吗? Drupal 框架处理用户管理/权限等的方式一直给我留下了深刻的印象...当然,它是基于 php 的,所以你应该感到宾至如归;)

我不知道你是否需要一个完整的-成熟的 CMS,但它可能会起作用。

Is this a project that you could use Drupal for? I've always been impressed with the way that the Drupal framework handles user management/privileges, etc... Of course, it's php based, so you should feel right at home ;)

I don't know if you need a full-fledged CMS, but it may do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文