├── simpleusers ├── su.inc.php ├── config.inc.php ├── install.php └── users.obj.php ├── logout.php ├── tables.sql ├── deleteuser.php ├── removeinfo.php ├── LICENSE.txt ├── csrf.php ├── login.php ├── newuser.php ├── changepassword.php ├── users.php ├── README.txt ├── userinfo.php ├── README.markdown ├── index.php └── reference.html /simpleusers/su.inc.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simpleusers/config.inc.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | logoutUser(); 16 | header("Location: index.php"); 17 | 18 | ?> -------------------------------------------------------------------------------- /tables.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS `users` ( 2 | `userId` int(11) NOT NULL auto_increment, 3 | `uUsername` varchar(128) NOT NULL, 4 | `uPassword` varchar(255) NOT NULL, 5 | `uActivity` datetime NOT NULL, 6 | `uCreated` datetime NOT NULL, 7 | PRIMARY KEY (`userId`), 8 | UNIQUE KEY `uUsername` (`uUsername`) 9 | ) ENGINE=MyISAM AUTO_INCREMENT=1 ; 10 | 11 | CREATE TABLE IF NOT EXISTS `users_information` ( 12 | `userId` int(11) NOT NULL, 13 | `infoKey` varchar(128) NOT NULL, 14 | `InfoValue` text NOT NULL, 15 | KEY `userId` (`userId`) 16 | ) ENGINE=MyISAM; 17 | -------------------------------------------------------------------------------- /deleteuser.php: -------------------------------------------------------------------------------- 1 | logged_in ) 17 | { 18 | header("Location: login.php"); 19 | exit; 20 | } 21 | 22 | // If the user is logged in, we can safely proceed. 23 | $userId = $_GET["userId"]; 24 | 25 | //Delete the user (plain and simple) 26 | $SimpleUsers->deleteUser($userId); 27 | header("Location: users.php"); 28 | 29 | ?> -------------------------------------------------------------------------------- /removeinfo.php: -------------------------------------------------------------------------------- 1 | logged_in ) 17 | { 18 | header("Location: login.php"); 19 | exit; 20 | } 21 | 22 | // If the user is logged in, we can safely proceed. 23 | 24 | $userId = $_GET["userId"]; 25 | $db_key = urldecode($_GET["db_key"]); 26 | 27 | $SimpleUsers->removeInfo($db_key, $userId); 28 | header("Location: users.php"); 29 | exit; 30 | 31 | 32 | ?> -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /csrf.php: -------------------------------------------------------------------------------- 1 | validateToken(); 19 | 20 | if($csrf) 21 | { 22 | // Proceed with the code to be executed if data hasn't been tampered 23 | } 24 | 25 | } // Validation end 26 | 27 | ?> 28 | 29 | 30 | 31 | 32 | 33 | 69 | 70 | 71 | 72 |

CSRF Protection

73 | 74 | 75 |

76 | 77 | CSRF successfully validated 78 | 79 | CSRF didn't validate - data probably have been tampered with! 80 | 81 |

82 | 83 | 84 |
85 |

86 |
87 | 88 | getToken(); ?> 89 |

90 |

91 | 92 |

93 | 94 |
95 | 96 | 97 | -------------------------------------------------------------------------------- /login.php: -------------------------------------------------------------------------------- 1 | loginUser($_POST["username"], $_POST["password"]); 20 | if(!$res) 21 | $error = "You supplied the wrong credentials."; 22 | else 23 | { 24 | header("Location: users.php"); 25 | exit; 26 | } 27 | 28 | } // Validation end 29 | 30 | ?> 31 | 32 | 33 | 34 | 35 | 36 | 72 | 73 | 74 | 75 |

Login

76 | 77 | 78 |

79 | 80 |

81 | 82 | 83 |
84 |

85 |
86 | 87 |

88 | 89 |

90 |
91 | 92 |

93 | 94 |

95 | 96 |

97 | 98 |
99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /newuser.php: -------------------------------------------------------------------------------- 1 | createUser($_POST["username"], $_POST["password"]); 25 | 26 | if(!$res) 27 | $error = "Username already taken."; 28 | else 29 | { 30 | header("Location: users.php"); 31 | exit; 32 | } 33 | } 34 | 35 | } // Validation end 36 | 37 | ?> 38 | 39 | 40 | 41 | 42 | 43 | 79 | 80 | 81 | 82 |

Register new user

83 | 84 | 85 |

86 | 87 |

88 | 89 | 90 |
91 |

92 |
93 | 94 |

95 | 96 |

97 |
98 | 99 |

100 | 101 |

102 | 103 |

104 | 105 |
106 | 107 | 108 | -------------------------------------------------------------------------------- /changepassword.php: -------------------------------------------------------------------------------- 1 | logged_in ) 17 | { 18 | header("Location: login.php"); 19 | exit; 20 | } 21 | 22 | // If the user is logged in, we can safely proceed. 23 | 24 | 25 | $userId = $_GET["userId"]; 26 | 27 | $user = $SimpleUsers->getSingleUser($userId); 28 | if( !$user ) 29 | die("The user could not be found..."); 30 | 31 | 32 | // Validation of input 33 | if( isset($_POST["password"]) ) 34 | { 35 | if( empty($_POST["password"]) ) 36 | $error = "You have to choose a password"; 37 | else 38 | { 39 | // Input validation is ok, set the password and then redirect 40 | $SimpleUsers->setPassword($_POST["password"], $user["userId"]); 41 | header("Location: users.php"); 42 | exit; 43 | } 44 | 45 | } // Validation end 46 | 47 | ?> 48 | 49 | 50 | 51 | 52 | 53 | 89 | 90 | 91 | 92 |

Change password for user

93 | 94 | 95 |

96 | 97 |

98 | 99 | 100 |
101 | 102 |

103 |
104 | 105 |

106 | 107 |

108 | 109 |

110 | 111 |
112 | 113 | 114 | -------------------------------------------------------------------------------- /users.php: -------------------------------------------------------------------------------- 1 | logged_in ) 17 | { 18 | header("Location: login.php"); 19 | exit; 20 | } 21 | 22 | // If the user is logged in, we can safely proceed. 23 | $users = $SimpleUsers->getUsers(); 24 | 25 | ?> 26 | 27 | 28 | 29 | 30 | 31 | 67 | 68 | 69 | 70 | 71 |

User administration

72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
UsernameLast activityCreated
84 | Create new user | Logout 85 |
">Delete | ">User info | ">Change password
99 | 100 | 101 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | SimpleUsers v2.0 2 | 3 | WARNING: 4 | This is a simple user management script that is currently only available because it's in use some places. If possible, find other solutions for your user management handling. 5 | 6 | SimpleUsers needs PHP 5.5, MySQL (no special version needed) and the MySQL Improved extension (http://php.net/mysqli). 7 | 8 | SKILLS 9 | Basic knowledge of PHP is required. Assuming that you know basic PHP, you most likely do know your way around HTML. 10 | 11 | IS IT SECURE 12 | SimpleUsers doesn't store password in clear text which makes the application secure for you AND your users. 13 | Every user gets a unique 128 character long salt prepended to their chosen password, 14 | which then gets stored in the database as a SHA1 hash. The hashing is one way. 15 | Additionally, to avoid SQL injection attacks, SimpleUsers uses prepared statements, when communicating with the database. 16 | 17 | CSRF (Cross-site request forgery) protection has been integrated - the methods doesn't require user is logged as CSRF also could be prefered in other situations.
18 | The CSRF protection works only with POST data (as GET data already is too easy to manipulate). 19 | 20 | 21 | Please be aware that SimpleUsers isn't a fullblown application; it's not safer than what you use SimpleUsers in. 22 | When developing your application, think of SimpleUsers as an aid in adding user management to your application. 23 | 24 | HOW TO INSTALL 25 | It's simple. 26 | What you need to do, is to edit the configuration file, located at simpleusers/config.inc.php, then run the install script which is located at simpleusers/install.php 27 | As an alternative to the install script, edit the configuration file. The tables can be created manually, by opening tables.sql and pasting the tables into phpMyAdmin. 28 | 29 | HOW DO I USE IT? 30 | Include and use 31 | You simply make sure that your sessions has been started (http://php.net/session_start), include the su.inc.file, located at simpleusers/su.inc.php and finally, you create an instance of the SimpleUsers object - now you're ready to go. 32 | 33 | Sample files are included with this package 34 | 35 | The following files are simply sample files and should not be used as useradministration `as is`. 36 | The sample files are only for reference and learning purposes, so you can build SimpleUsers into your own application. 37 | - users.php - A simple administration interface to manage registered users (login required). 38 | - userinfo.php - A simple administration interface to manage registered data to a specific user (login required). 39 | - removeinfo.php - A simple example of how to permanently remove specific data registered to a specific user (login required) 40 | - deleteuser.php - A simple example of how to delete users (login required). 41 | - changepassword.php - A simple example of how to change a users password (login required). 42 | - logout.php - A simple example of how to log out a user. 43 | - login.php - A simple example of how to log in a user. 44 | - newuser.php - A simple example of how to create a new user. 45 | - csrf.php - A simple example of how to use and implement CSRF protection. 46 | 47 | Not all the methods available in SimpleUsers is covered in these files. 48 | A full reference can be found in reference.html. 49 | 50 | 51 | TROUBLESHOOTING 52 | Please make sure you configured the config file! 53 | It might seem like a trivial thing to mention, but when things doesn't work as expected, the most likely cause is a misconfigured configuration file. 54 | The config file is located at simpleusers/config.inc.php and is fairly simple to understand. 55 | 56 | Did you run the install script? 57 | If not, you would probably want to; this will create the tables in your database needed for this to work. 58 | The install script is located at simpleusers/install.php. 59 | If you did, you should remove or rename the file or something similar, to avoid unwelcome users having access to it. 60 | -------------------------------------------------------------------------------- /simpleusers/install.php: -------------------------------------------------------------------------------- 1 | connect_error ) 22 | { 23 | $error = true; 24 | $title = "MySQL Connection failed!"; 25 | $message = "Did you remember to edit config.inc.php? MySQL said: ".$mysqli->connect_error; 26 | } 27 | 28 | if(isset($_POST["step"])) 29 | $install = true; 30 | 31 | 32 | $tables["users"] = "CREATE TABLE IF NOT EXISTS `users` ( 33 | `userId` int(11) NOT NULL auto_increment, 34 | `uUsername` varchar(128) NOT NULL, 35 | `uPassword` varchar(40) NOT NULL, 36 | `uSalt` varchar(128) NOT NULL, 37 | `uActivity` datetime NOT NULL, 38 | `uCreated` datetime NOT NULL, 39 | PRIMARY KEY (`userId`), 40 | UNIQUE KEY `uUsername` (`uUsername`) 41 | ) ENGINE=MyISAM AUTO_INCREMENT=1 ;"; 42 | 43 | $tables["users_information"] = "CREATE TABLE IF NOT EXISTS `users_information` ( 44 | `userId` int(11) NOT NULL, 45 | `infoKey` varchar(128) NOT NULL, 46 | `InfoValue` text NOT NULL, 47 | KEY `userId` (`userId`) 48 | ) ENGINE=MyISAM;"; 49 | 50 | 51 | 52 | 53 | 54 | 55 | ?> 56 | 57 | 58 | 59 | SimpleUsers Installation 60 | 61 | 81 | 82 | 83 |

Installation of SimpleUsers

84 | 85 | 86 |

87 | 88 |

89 |

90 | 91 |

92 | 93 | 94 |
95 | 96 |

97 | Ready to install 98 |

99 |

100 | 101 | When ready to proceed, press `Install!` - when your'e done, consider deleting, moving or renaming this install script for security purposes.
102 |

103 | 104 |

105 | 106 | 107 |

108 | Creating database tables 109 |

110 | 111 | $query ): ?> 112 |

113 | prepare($query) ) 115 | { 116 | if( $stmt->execute() ) 117 | $status = "done..."; 118 | else 119 | $status = "failed! MySQL returned: ".$stmt->error; 120 | } 121 | else 122 | $status = "failed! MySQL returned: ".$mysqli->error; 123 | ?> 124 | Table ``: 125 |

126 | 127 | 128 | 129 |
130 | 131 |
132 | 133 | -------------------------------------------------------------------------------- /userinfo.php: -------------------------------------------------------------------------------- 1 | logged_in ) 17 | { 18 | header("Location: login.php"); 19 | exit; 20 | } 21 | 22 | // If the user is logged in, we can safely proceed. 23 | 24 | 25 | $userId = $_GET["userId"]; 26 | 27 | $user = $SimpleUsers->getSingleUser($userId); 28 | if( !$user ) 29 | die("The user could not be found..."); 30 | 31 | $userInfo = $SimpleUsers->getInfoArray($userId); 32 | 33 | if( isset($_POST["newkey"]) ) 34 | { 35 | if( strlen($_POST["newkey"]) > 0 ) { 36 | 37 | try { 38 | $SimpleUsers->setInfo($_POST["newkey"], $_POST["newvalue"], $userId); 39 | } 40 | catch (Exception $e) { 41 | // Ignore errors for this demo purpose 42 | } 43 | 44 | 45 | } 46 | if( isset($_POST["userInfo"]) ) 47 | { 48 | 49 | foreach ($_POST["userInfo"] as $pKey => $pValue) { 50 | try { 51 | $SimpleUsers->setInfo($pKey, $pValue, $userId); 52 | } 53 | catch (Exception $e) { 54 | // Ignore errors for this demo purpose 55 | } 56 | 57 | } 58 | 59 | } 60 | 61 | header("Location: users.php"); 62 | exit; 63 | } 64 | 65 | 66 | 67 | ?> 68 | 69 | 70 | 71 | 72 | 73 | 109 | 110 | 111 | 112 |

User information for

113 | 114 | 115 |

116 | 117 |

118 | 119 | 120 |
121 | 122 | $value): ?> 123 |

124 |
125 |
126 | Permanently remove this key 127 |

128 | 129 |

Create new database key?

130 |

131 |
132 | 133 |

134 | 135 |

136 |
137 | 138 |

139 | 140 | 141 |

142 | 143 |

144 | 145 |
146 | 147 | 148 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | SimpleUsers v2.0 2 | ================ 3 | 4 | 5 | ##WARNING: 6 | This is a simple user management script that is currently only available because it's in use some places. If possible, find other solutions for your user management handling. 7 | 8 | Requirements 9 | ------------ 10 | 11 | SimpleUsers needs PHP 5.5, MySQL (no special version needed) and the MySQL Improved extension (http://php.net/mysqli). 12 | 13 | SKILLS 14 | ------ 15 | Basic knowledge of PHP is required. Assuming that you know basic PHP, you most likely do know your way around HTML. 16 | 17 | IS IT SECURE? 18 | ------------- 19 | SimpleUsers doesn't store password in clear text which makes the application secure for you AND your users. 20 | Every user gets a unique 128 character long salt prepended to their chosen password, 21 | which then gets stored in the database as a SHA1 hash. The hashing is one way. 22 | Additionally, to avoid SQL injection attacks, SimpleUsers uses prepared statements, when communicating with the database. 23 | 24 | CSRF (Cross-site request forgery) protection has been integrated - the methods doesn't require user is logged as CSRF also could be prefered in other situations.
25 | The CSRF protection works only with POST data (as GET data already is too easy to manipulate). 26 | 27 | 28 | Please be aware that SimpleUsers isn't a fullblown application; it's not safer than what you use SimpleUsers in. 29 | When developing your application, think of SimpleUsers as an aid in adding user management to your application. 30 | 31 | HOW TO INSTALL 32 | -------------- 33 | It's simple. 34 | What you need to do, is to edit the configuration file, located at simpleusers/config.inc.php, then run the install script which is located at simpleusers/install.php 35 | As an alternative to the install script, edit the configuration file. The tables can be created manually, by opening tables.sql and pasting the tables into phpMyAdmin. 36 | 37 | HOW DO I USE IT? 38 | ---------------- 39 | Include and use 40 | You simply make sure that your sessions has been started (http://php.net/session_start), include the su.inc.file, located at simpleusers/su.inc.php and finally, you create an instance of the SimpleUsers object - now you're ready to go. 41 | 42 | Sample files are included with this package 43 | 44 | The following files are simply sample files and should not be used as useradministration 'as is'. 45 | The sample files are only for reference and learning purposes, so you can build SimpleUsers into your own application. 46 | 47 | * users.php - A simple administration interface to manage registered users (login required). 48 | * userinfo.php - A simple administration interface to manage registered data to a specific user (login required). 49 | * removeinfo.php - A simple example of how to permanently remove specific data registered to a specific user (login required) 50 | * deleteuser.php - A simple example of how to delete users (login required). 51 | * changepassword.php - A simple example of how to change a users password (login required). 52 | * logout.php - A simple example of how to log out a user. 53 | * login.php - A simple example of how to log in a user. 54 | * newuser.php - A simple example of how to create a new user. 55 | * csrf.php - A simple example of how to use and implement CSRF protection. 56 | 57 | Not all the methods available in SimpleUsers is covered in these files. 58 | A full reference can be found in reference.html. 59 | 60 | 61 | TROUBLESHOOTING 62 | --------------- 63 | Please make sure you configured the config file! 64 | It might seem like a trivial thing to mention, but when things doesn't work as expected, the most likely cause is a misconfigured configuration file. 65 | The config file is located at simpleusers/config.inc.php and is fairly simple to understand. 66 | 67 | Did you run the install script? 68 | If not, you would probably want to; this will create the tables in your database needed for this to work. 69 | The install script is located at simpleusers/install.php. 70 | If you did, you should remove or rename the file or something similar, to avoid unwelcome users having access to it. 71 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 47 | 48 | 49 | 50 |

SimpleUsers

51 | 52 |

The application

53 |

54 | Software 55 |

56 |

57 | SimpleUsers needs PHP 5, MySQL (no special version needed) and the MySQL Improved extension (http://php.net/mysqli). 58 |

59 | 60 | 61 |

62 | Skills 63 |

64 |

65 | Basic knowledge of PHP is required. Assuming that you know basic PHP, you most likely do know your way around HTML. 66 |

67 | 68 |

69 | Is it secure? 70 |

71 |

72 | SimpleUsers doesn't store password in clear text which makes the application secure for you AND your users.
73 | Every user gets a unique 128 character long salt prepended to their chosen password, 74 | which then gets stored in the database as a SHA1 hash. The hashing is one way.
75 | Additionally, to avoid SQL injection attacks, SimpleUsers uses prepared statements, when communicating with the database. 76 |

77 | 78 |

79 | CSRF (Cross-site request forgery) protection has been integrated - the methods doesn't require user is logged as CSRF also could be prefered in other situations.
80 | The CSRF protection works only with POST data (as GET data already is too easy to manipulate). 81 |

82 | 83 |

84 | Please be aware that SimpleUsers isn't a fullblown application; it's not safer than what you use SimpleUsers in.
85 | When developing your application, think of SimpleUsers as an aid in adding user management to your application. 86 |

87 | 88 |

How to install

89 |

90 | It's simple.
91 | What you need to do, is to edit the configuration file, located at simpleusers/config.inc.php, then run the install script which is located at simpleusers/install.php 92 |

93 | 94 |

How do I use it?

95 | 96 |

97 | Include and use 98 |

99 |

100 | You simply make sure that your sessions has been started (http://php.net/session_start), include the su.inc.file, located at simpleusers/su.inc.php 101 | and finally, you create an instance of the SimpleUsers object - now you're ready to go. 102 |

103 | 104 |

105 | Sample files are included with this package 106 |

107 |

108 | The following files are simply sample files and should not be used as useradministration `as is`.
109 | The sample files are only for reference and learning purposes, so you can build SimpleUsers into your own application. 110 |

111 | 122 |

123 | Not all the methods available in SimpleUsers is covered in these files.
124 | A full reference can be found in reference.html. 125 |

126 | 127 |

Troubleshooting

128 | 129 |

130 | Please make sure you configured the config file! 131 |

132 |

133 | It might seem like a trivial thing to mention, but when things doesn't work as expected, the most likely cause is a misconfigured configuration file.
134 | The config file is located at simpleusers/config.inc.php and is fairly simple to understand. 135 |

136 | 137 | 138 |

139 | Did you run the install script? 140 |

141 |

142 | If not, you would probably want to; this will create the tables in your database needed for this to work.
143 | The install script is located at simpleusers/install.php. 144 |

145 |

146 | If you did, you should remove or rename the file or something similar, to avoid unwelcome users having access to it. 147 |

148 | 149 | 150 | -------------------------------------------------------------------------------- /simpleusers/users.obj.php: -------------------------------------------------------------------------------- 1 | Please add `session_start();` initially in your file before any output."); 32 | } 33 | 34 | $this->mysqli = new mysqli($GLOBALS["mysql_hostname"], $GLOBALS["mysql_username"], $GLOBALS["mysql_password"], $GLOBALS["mysql_database"]); 35 | if ($this->mysqli->connect_error) { 36 | throw new Exception("MySQL connection could not be established: " . $this->mysqli->connect_error); 37 | } 38 | 39 | $this->_validateUser(); 40 | $this->_populateUserdata(); 41 | $this->_updateActivity(); 42 | } 43 | 44 | /** 45 | * Returns a (int)user id, if the user was created succesfully. 46 | * If not, it returns (bool)false. 47 | * 48 | * @param $username 49 | * @param $password 50 | * @return bool|int 51 | * @throws Exception 52 | */ 53 | 54 | public function createUser($username, $password) 55 | { 56 | $password = password_hash($password, PASSWORD_DEFAULT); 57 | 58 | $sql = "INSERT INTO users VALUES (NULL, ?, ?, NOW(), NOW())"; 59 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 60 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 61 | } 62 | 63 | $this->stmt->bind_param("ss", $username, $password); 64 | if ($this->stmt->execute()) { 65 | return $this->stmt->insert_id; 66 | } 67 | 68 | return false; 69 | } 70 | 71 | /** 72 | * Pairs up username and password as registrered in the database. 73 | * If the username and password is correct, it will return (int)user id of 74 | * the user which credentials has been passed and set the session, for 75 | * use by the user validating. 76 | * 77 | * @param $username 78 | * @param $password 79 | * @return bool 80 | * @throws Exception 81 | */ 82 | 83 | public function loginUser($username, $password) 84 | { 85 | $sql = "SELECT userId, uPassword FROM users WHERE uUsername=? LIMIT 1"; 86 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 87 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 88 | } 89 | 90 | $this->stmt->bind_param("s", $username); 91 | $this->stmt->execute(); 92 | $this->stmt->store_result(); 93 | 94 | if ($this->stmt->num_rows == 0) { 95 | return false; 96 | } 97 | 98 | $this->stmt->bind_result($userId, $userPassword); 99 | $this->stmt->fetch(); 100 | 101 | 102 | if(!password_verify($password, $userPassword)) { 103 | return false; 104 | } 105 | 106 | $_SESSION[$this->sessionName]["userId"] = $userId; 107 | $this->logged_in = true; 108 | 109 | return $userId; 110 | } 111 | 112 | /** 113 | * Sets an information pair, consisting of a key name and that keys value. 114 | * The information can be retrieved with this objects getInfo() method. 115 | * 116 | * @param $key 117 | * @param $value 118 | * @param null $userId Can be used if administrative control is needed 119 | * @return bool 120 | * @throws Exception 121 | */ 122 | 123 | public function setInfo($key, $value, $userId = null) 124 | { 125 | if ($userId == null) { 126 | if (!$this->logged_in) 127 | return false; 128 | } 129 | 130 | $reservedKeys = array("userId", "uUsername", "uActivity", "uCreated", "uLevel"); 131 | if (in_array($key, $reservedKeys)) 132 | throw new Exception("User information key \"" . $key . "\" is reserved for internal use!"); 133 | 134 | if ($userId == null) 135 | $userId = $_SESSION[$this->sessionName]["userId"]; 136 | 137 | if ($this->getInfo($key, $userId)) { 138 | $sql = "UPDATE users_information SET infoValue=? WHERE infoKey=? AND userId=? LIMIT 1"; 139 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 140 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 141 | } 142 | 143 | $this->stmt->bind_param("ssi", $value, $key, $userId); 144 | $this->stmt->execute(); 145 | } else { 146 | $sql = "INSERT INTO users_information VALUES (?, ?, ?)"; 147 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 148 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 149 | } 150 | 151 | $this->stmt->bind_param("iss", $userId, $key, $value); 152 | $this->stmt->execute(); 153 | } 154 | 155 | return true; 156 | } 157 | 158 | /** 159 | * Use this function to retrieve user information attached to a certain user 160 | * that has been set by using this objects setInfo() method. 161 | * 162 | * @param $key 163 | * @param null $userId Can be used if administrative control is needed 164 | * @return bool|string 165 | * @throws Exception 166 | */ 167 | 168 | public function getInfo($key, $userId = null) 169 | { 170 | 171 | if ($userId == null) { 172 | if (!$this->logged_in) 173 | return false; 174 | 175 | $userId = $_SESSION[$this->sessionName]["userId"]; 176 | } 177 | 178 | $sql = "SELECT infoValue FROM users_information WHERE userId=? AND infoKey=? LIMIT 1"; 179 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 180 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 181 | } 182 | 183 | $this->stmt->bind_param("is", $userId, $key); 184 | $this->stmt->execute(); 185 | $this->stmt->store_result(); 186 | 187 | if ($this->stmt->num_rows == 0) { 188 | return ""; 189 | } 190 | 191 | $this->stmt->bind_result($value); 192 | $this->stmt->fetch(); 193 | 194 | return $value; 195 | 196 | } 197 | 198 | /** 199 | * Use this function to permanently remove information attached to a certain user 200 | * that has been set by using this objects setInfo() method. 201 | * 202 | * @param $key 203 | * @param null $userId Can be used if administrative control is needed 204 | * @return bool 205 | * @throws Exception 206 | */ 207 | 208 | public function removeInfo($key, $userId = null) 209 | { 210 | 211 | if ($userId == null) { 212 | if (!$this->logged_in) { 213 | return false; 214 | } 215 | 216 | $userId = $_SESSION[$this->sessionName]["userId"]; 217 | } 218 | 219 | $sql = "DELETE FROM users_information WHERE userId=? AND infoKey=? LIMIT 1"; 220 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 221 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 222 | } 223 | 224 | $this->stmt->bind_param("is", $userId, $key); 225 | $this->stmt->execute(); 226 | 227 | if ($this->stmt->affected_rows > 0) { 228 | return true; 229 | } 230 | 231 | return false; 232 | } 233 | 234 | 235 | /** 236 | * Use this function to retrieve all user information attached to a certain user 237 | * that has been set by using this objects setInfo() method into an array. 238 | * 239 | * @param null $userId 240 | * @return array|bool 241 | * @throws Exception 242 | */ 243 | 244 | public function getInfoArray($userId = null) 245 | { 246 | if ($userId == null) { 247 | 248 | if (!$this->logged_in) { 249 | return false; 250 | } 251 | 252 | $userId = $_SESSION[$this->sessionName]["userId"]; 253 | } 254 | 255 | $sql = "SELECT infoKey, infoValue FROM users_information WHERE userId=? ORDER BY infoKey ASC"; 256 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 257 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 258 | } 259 | 260 | $this->stmt->bind_param("i", $userId); 261 | $this->stmt->execute(); 262 | $this->stmt->store_result(); 263 | 264 | $userInfo = array(); 265 | if ($this->stmt->num_rows > 0) { 266 | $this->stmt->bind_result($key, $value); 267 | while ($this->stmt->fetch()) { 268 | $userInfo[$key] = $value; 269 | } 270 | } 271 | 272 | $user = $this->getSingleUser($userId); 273 | $userInfo = array_merge($userInfo, $user); 274 | asort($userInfo); 275 | 276 | return $userInfo; 277 | } 278 | 279 | /** 280 | * Logout the active user, unsetting the userId session. 281 | * This is a void function 282 | */ 283 | 284 | public function logoutUser() 285 | { 286 | if (isset($_SESSION[$this->sessionName])) { 287 | unset($_SESSION[$this->sessionName]); 288 | } 289 | 290 | $this->logged_in = false; 291 | } 292 | 293 | /** 294 | * Update the users password with this function. 295 | * Generates a new salt and a sets the users password with the given parameter 296 | * 297 | * @param $password 298 | * @param null $userId Can be used if administrative control is needed 299 | * @return bool 300 | * @throws Exception 301 | */ 302 | 303 | public function setPassword($password, $userId = null) 304 | { 305 | 306 | if ($userId == null) { 307 | $userId = $_SESSION[$this->sessionName]["userId"]; 308 | } 309 | 310 | $password = password_hash($password, PASSWORD_DEFAULT); 311 | 312 | $sql = "UPDATE users SET uPassword=? WHERE userId=? LIMIT 1"; 313 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 314 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 315 | } 316 | 317 | $this->stmt->bind_param("si", $password,$userId); 318 | return $this->stmt->execute(); 319 | } 320 | 321 | /** 322 | * Returns an array with each user in the database. 323 | * 324 | * @return array 325 | */ 326 | 327 | public function getUsers() 328 | { 329 | 330 | $sql = "SELECT DISTINCT userId, uUsername, uActivity, uCreated FROM users ORDER BY uUsername ASC"; 331 | 332 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 333 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 334 | } 335 | 336 | $this->stmt->execute(); 337 | $this->stmt->store_result(); 338 | 339 | if ($this->stmt->num_rows == 0) { 340 | return array(); 341 | } 342 | 343 | $this->stmt->bind_result($userId, $username, $activity, $created); 344 | 345 | $users = array(); 346 | 347 | $i = 0; 348 | while ($this->stmt->fetch()) { 349 | $users[$i]["userId"] = $userId; 350 | $users[$i]["uUsername"] = $username; 351 | $users[$i]["uActivity"] = $activity; 352 | $users[$i]["uCreated"] = $created; 353 | 354 | $i++; 355 | } 356 | 357 | return $users; 358 | 359 | } 360 | 361 | /** 362 | * Gets the basic info for a single user based on the userId 363 | * 364 | * @param null $userId Can be used if administrative control is needed 365 | * @return bool 366 | * @throws Exception 367 | */ 368 | 369 | public function getSingleUser($userId = null) 370 | { 371 | 372 | if ($userId == null) { 373 | $userId = $_SESSION[$this->sessionName]["userId"]; 374 | } 375 | 376 | $sql = "SELECT userId, uUsername, uActivity, uCreated FROM users WHERE userId=? LIMIT 1"; 377 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 378 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 379 | } 380 | 381 | $this->stmt->bind_param("i", $userId); 382 | $this->stmt->execute(); 383 | $this->stmt->store_result(); 384 | 385 | if ($this->stmt->num_rows == 0) { 386 | return false; 387 | } 388 | 389 | $this->stmt->bind_result($userId, $username, $activity, $created); 390 | $this->stmt->fetch(); 391 | 392 | $user["userId"] = $userId; 393 | $user["uUsername"] = $username; 394 | $user["uActivity"] = $activity; 395 | $user["uCreated"] = $created; 396 | 397 | return $user; 398 | 399 | } 400 | 401 | /** 402 | * Deletes all information regarding a user. 403 | * This is a void function. 404 | * 405 | * @param $userId 406 | * @throws Exception 407 | */ 408 | 409 | public function deleteUser($userId) 410 | { 411 | $sql = "DELETE FROM users WHERE userId=?"; 412 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 413 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 414 | } 415 | 416 | $this->stmt->bind_param("i", $userId); 417 | $this->stmt->execute(); 418 | 419 | $sql = "DELETE FROM users_information WHERE userId=?"; 420 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 421 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 422 | } 423 | 424 | $this->stmt->bind_param("i", $userId); 425 | $this->stmt->execute(); 426 | } 427 | 428 | /** 429 | * Returns a hidden input field with a unique token value 430 | * for CSRF to be used with post data. 431 | * The token is saved in a session for later validation. 432 | * 433 | * @param bool $xhtml 434 | * @return string 435 | */ 436 | 437 | public function getToken($xhtml = true) 438 | { 439 | $token = uniqid($this->sessionName, true); 440 | $name = "token_" . md5($token); 441 | 442 | $_SESSION[$this->sessionName]["csrf_name"] = $name; 443 | $_SESSION[$this->sessionName]["csrf_token"] = $token; 444 | 445 | $string = "sessionName]["csrf_name"]; 464 | $token = $_SESSION[$this->sessionName]["csrf_token"]; 465 | unset($_SESSION[$this->sessionName]["csrf_token"]); 466 | unset($_SESSION[$this->sessionName]["csrf_name"]); 467 | 468 | if ($_POST[$name] == $token) 469 | return true; 470 | 471 | return false; 472 | } 473 | 474 | /** 475 | * This function updates the users last activity time 476 | * This is a void function. 477 | */ 478 | 479 | private function _updateActivity() 480 | { 481 | if (!$this->logged_in) { 482 | return; 483 | } 484 | 485 | $userId = $_SESSION[$this->sessionName]["userId"]; 486 | 487 | $sql = "UPDATE users SET uActivity=NOW() WHERE userId=? LIMIT 1"; 488 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 489 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 490 | } 491 | 492 | $this->stmt->bind_param("i", $userId); 493 | $this->stmt->execute(); 494 | 495 | } 496 | 497 | /** 498 | * Validates if the user is logged in or not. 499 | * This is a void function. 500 | */ 501 | 502 | private function _validateUser() 503 | { 504 | if (!isset($_SESSION[$this->sessionName]["userId"])) { 505 | return; 506 | } 507 | 508 | if (!$this->_validateUserId()) { 509 | return; 510 | } 511 | 512 | $this->logged_in = true; 513 | } 514 | 515 | /** 516 | * Validates if the user id, in the session is still valid. 517 | * 518 | * @return bool 519 | * @throws Exception 520 | */ 521 | 522 | private function _validateUserId() 523 | { 524 | $userId = $_SESSION[$this->sessionName]["userId"]; 525 | 526 | $sql = "SELECT userId FROM users WHERE userId=? LIMIT 1"; 527 | if (!$this->stmt = $this->mysqli->prepare($sql)) { 528 | throw new Exception("MySQL Prepare statement failed: " . $this->mysqli->error); 529 | } 530 | 531 | $this->stmt->bind_param("i", $userId); 532 | $this->stmt->execute(); 533 | $this->stmt->store_result(); 534 | 535 | if ($this->stmt->num_rows == 1) { 536 | return true; 537 | } 538 | 539 | $this->logoutUser(); 540 | 541 | return false; 542 | } 543 | 544 | /** 545 | * Populates the current users data information for 546 | * quick access as an object. 547 | * 548 | * @return void 549 | * @throws Exception 550 | */ 551 | 552 | private function _populateUserdata() 553 | { 554 | $this->userdata = array(); 555 | 556 | if ($this->logged_in) { 557 | $data = $this->getInfoArray(); 558 | foreach ($data as $key => $value) { 559 | $this->userdata[$key] = $value; 560 | } 561 | } 562 | } 563 | 564 | } 565 | 566 | ?> -------------------------------------------------------------------------------- /reference.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 47 | 48 | 49 | 50 |

SimpleUsers Method and Member reference

51 | 52 |

Index

53 | 68 | 69 |

Methods

70 |

71 | SimpleUsers::__construct() 72 |

73 |

74 | Object construct verifies that a session has been started and that a MySQL connection can be established.
75 | It takes no parameters. 76 |

77 |

78 |

79 | Example 80 | 81 | <?php
    $SimpleUsers 
= new SimpleUsers();
?>
82 | 83 |
84 |
85 |

86 | 87 |

88 | SimpleUsers::createUser( string $username, string $password ) 89 |

90 |

91 | Returns a (int)user id, if the user was created succesfully. 92 | If not, it returns (bool)false. 93 |

94 |

95 |

96 | Example 97 | 98 | <?php 99 |
100 |
    $SimpleUsers 
= new SimpleUsers(); 101 |
     102 |
    
$res $SimpleUsers->createUser("John""qwerty"); 103 |
    if( 
$res ) 104 |
        echo 
"User was created with userId: ".$res; 105 |
    else 106 |
        echo 
"The username was already taken."; 107 |
108 |
?> 109 |
110 |
111 |
112 |

113 | 114 | 115 |

116 | SimpleUsers::loginUser( string $username, string $password ) 117 |

118 |

119 | Pairs up username and password as registrered in the database.
120 | If the username and password is correct, it will return (int)user id of 121 | the user which credentials has been passed and set the session, for 122 | use by the user validating. 123 |

124 |

125 |

126 | Example 127 | 128 | <?php 129 |
130 |
    $SimpleUsers 
= new SimpleUsers(); 131 |
132 |
    
$res $SimpleUsers->loginUser("John""qwerty"); 133 |
     134 |
    if( 
$res ) 135 |
    { 136 |
        
header("Location: ..."); 137 |
        exit; 138 |
    }     139 |
    else 140 |
    { 141 |
        echo 
"You passed the wrong credentials."; 142 |
    } 143 |
144 |
?> 145 |
146 |
147 |
148 |

149 | 150 |

151 | SimpleUsers::setInfo( string $key, string $value [, int $userId] ) 152 |

153 |

154 | Sets a custom information pair, consisting of a key name and that keys value for a user. 155 | Setting the third parameter sets the provided information for a given user, instead of the one calling it. 156 |

157 |

158 |

159 | Example #1 160 | 161 | <?php 162 |
163 |
    $SimpleUsers 
= new SimpleUsers(); 164 |
165 |
    
// Store information for the current user 166 |
    
$SimpleUsers->setInfo("fullname""John Doe"); 167 |
?> 168 |
169 |
170 |
171 |

172 | 173 |

174 |

175 | Example #2 176 | 177 | <?php 178 |
179 |
    $SimpleUsers 
= new SimpleUsers(); 180 |
181 |
    
// Store information for the user with userId provided in the third parameter. 182 |
    // This is useful for administrators when wanting to assign, edit or empty stored information about a user 183 |
    
$SimpleUsers->setInfo("fullname""John Doe"354); 184 |
?> 185 |
186 |
187 |
188 |

189 | 190 |

191 | SimpleUsers::getInfo( string $key [, int $userId] ) 192 |

193 |

194 | Use this function to retrieve stored custom user information.
195 | Setting the third parameter gets the stored information for a given user, instead of the one calling it. 196 |

197 |

198 |

199 | Example #1 200 | 201 | <?php 202 |
203 |
    $SimpleUsers 
= new SimpleUsers(); 204 |
205 |
    
// Get stored information for the active user 206 |
    
$fullname $SimpleUsers->getInfo("fullname"); 207 |
?> 208 |
209 |
210 |
211 |

212 | 213 |

214 |

215 | Example #2 216 | 217 | <?php 218 |
219 |
    $SimpleUsers 
= new SimpleUsers(); 220 |
221 |
    
// Get stored information for the user with userId provided in the third parameter. 222 |
    // This is useful for administrators when wanting to retrieve stored information about a user 223 |
    
$fullname $SimpleUsers->getInfo("fullname"354); 224 |
?> 225 |
226 |
227 |
228 |

229 | 230 | 231 |

232 | SimpleUsers::getInfoArray( [int $userId] ) 233 |

234 |

235 | Returns an associative array with all the custom information stored about the current user.
236 | Passing a userId as a parameter will return an associative array with all the custom information for that specific user. 237 |

238 |

239 |

240 | Example #1 241 | 242 | <?php 243 |
244 |
    $SimpleUsers 
= new SimpleUsers(); 245 |
246 |
    
// Gets all stored information for the active user and returns an associative array 247 |
    
$info $SimpleUsers->getInfoArray(); 248 |
     249 |
    
print_r($info); 250 |
?> 251 |
252 |
253 |
254 |

255 | 256 |

257 |

258 | Example #2 259 | 260 | <?php 261 |
262 |
    $SimpleUsers 
= new SimpleUsers(); 263 |
264 |
    
// Gets all stored information for a given user and returns an associative array 265 |
    // This is useful for administrators when wanting to get all stored information about a user  266 |
    
$info $SimpleUsers->getInfoArray(354); 267 |
     268 |
    
print_r($info); 269 |
?> 270 |
271 |
272 |
273 |

274 | 275 |

276 | SimpleUsers::logoutUser() 277 |

278 |

279 | Logout the active user, unsetting the users session. 280 |

281 |

282 |

283 | Example 284 | 285 | <?php 286 |
287 |
    $SimpleUsers 
= new SimpleUsers(); 288 |
289 |
    
$SimpleUsers->logoutUser(); 290 |
?> 291 |
292 |
293 |
294 |

295 | 296 |

297 | SimpleUsers::setPassword( string $password [, int $userId] ) 298 |

299 |

300 | Update the users password with this function.
301 | It generates a new salt and a sets the users password provided by the first parameter.
302 | Providing a userId in the second paramater will set the password for that specific user. 303 |

304 |

305 |

306 | Example #1 307 | 308 | <?php 309 |
310 |
    $SimpleUsers 
= new SimpleUsers(); 311 |
312 |
    
// Sets a new password for the current active user 313 |
    
$SimpleUsers->setPassword("difficult"); 314 |
?> 315 |
316 |
317 |
318 |

319 | 320 |

321 |

322 | Example #2 323 | 324 | <?php 325 |
326 |
    $SimpleUsers 
= new SimpleUsers(); 327 |
328 |
    
// Sets a new password for the userId identified by the second parameter. 329 |
    // This is useful if an administrative action is needed for setting a new password. 330 |
    
$SimpleUsers->setPassword("difficult"354); 331 |
?> 332 |
333 |
334 |
335 |

336 | 337 | 338 |

339 | SimpleUsers::getUsers() 340 |

341 |

342 | Gives you an array with all registered users and their basic information (last activity, creation date, username and userId) 343 |

344 |

345 |

346 | Example 347 | 348 | <?php 349 |
350 |
    $SimpleUsers 
= new SimpleUsers(); 351 |
352 |
    
$users $SimpleUsers->getUsers(); 353 |
354 |
    
print_r($users); 355 |
?> 356 |
357 |
358 |
359 |

360 | 361 | 362 |

363 | SimpleUsers::getSingleUser( [int $userId] ) 364 |

365 |

366 | Gives you an associative array, containing the basic information (last activity, creation date, username and userId) for the current active user.
367 | If a userId is provided as parameter, the returned associative array will contain the basic information for that specific user. 368 |

369 |

370 |

371 | Example #1 372 | 373 | <?php 374 |
375 |
    $SimpleUsers 
= new SimpleUsers(); 376 |
377 |
    
$user $SimpleUsers->getSingleUser(); 378 |
379 |
    
print_r($user); 380 |
?> 381 |
382 |
383 |
384 |

385 | 386 |

387 |

388 | Example #2 389 | 390 | <?php 391 |
392 |
    $SimpleUsers 
= new SimpleUsers(); 393 |
394 |
    
// Retrieving the basic information for a specific user. 395 |
    // This is useful for administrative purposes. 396 |
    
$user $SimpleUsers->getSingleUser(354); 397 |
398 |
    
print_r($user); 399 |
?> 400 |
401 |
402 |
403 |

404 | 405 |

406 | SimpleUsers::deleteUser( int $userId ) 407 |

408 |

409 | Deletes a given user and stored custom information with it. 410 |

411 |

412 |

413 | Example 414 | 415 | <?php 416 |
417 |
    $SimpleUsers 
= new SimpleUsers(); 418 |
419 |
    
$SimpleUsers->deleteUser(354); 420 |
?> 421 |
422 |
423 |
424 |

425 | 426 |

427 | SimpleUsers::getToken( [bool] ) 428 |

429 |

430 | Returns a hidden input field with a unique token value for CSRF to be used with post data.
431 | The token is saved in a session for later validation.
432 | The boolean parameter is default set to true which returns the input field as XHTML - provide (bool) false for HTML 4 compliance. 433 |

434 |

435 |

436 | Example 437 | 438 | <?php 439 |
    $SimpleUsers 
= new SimpleUsers();  440 |
?> 441 |
<form method="post" action="..."> 442 |
    <input ...> 443 |
    <?php echo $SimpleUsers->getToken(); ?> 444 |
</form> 445 |
446 |
447 |
448 |

449 | 450 |

451 | SimpleUsers::validateToken() 452 |

453 |

454 | Use this method when you wish to validate the CSRF token from your post data.
455 | The method returns true upon validation, otherwise false. 456 |

457 |

458 |

459 | Example 460 | 461 | <?php 462 |
463 |
    $SimpleUsers 
= new SimpleUsers(); 464 |
465 |
    
$csrf $SimpleUsers->validateToken(); 466 |
     467 |
    if(!
$csrf) 468 |
    { 469 |
        
header("Location: request_denied.php"); 470 |
        exit; 471 |
    } 472 |
     473 |
    
// Otherwise, continue with processing 474 |
475 |
?> 476 |
477 |
478 |
479 |

480 | 481 |

Members

482 | 483 |

484 | SimpleUsers::logged_in 485 |

486 |

487 | This tells wether a user is logged in or not.
488 | Value is (bool)true or (bool)false. 489 |

490 |

491 |

492 | Example 493 | 494 | <?php 495 |
496 |
    $SimpleUsers 
= new SimpleUsers(); 497 |
498 |
    if( 
$SimpleUsers->logged_in ) 499 |
        echo 
"You are logged in"; 500 |
    else 501 |
        echo 
"You are NOT logged in!"; 502 |
?> 503 |
504 |
505 |
506 |

507 | 508 | 509 |

510 | SimpleUsers::userdata 511 |

512 |

513 | This is auto-populated array containing the information stored for the logged in user.
514 | If no user is logged in, this member consists of an empty array. 515 |

516 |

517 |

518 | Example 519 | 520 | <?php 521 |
522 |
    $SimpleUsers 
= new SimpleUsers(); 523 |
524 |
    if( 
$SimpleUsers->logged_in ) 525 |
        echo 
"Hello " $SimpleUsers->userdata["uUsername"] . " - your last activity was at " $SimpleUsers->userdata["uActivity"]; 526 |
527 |
?> 
528 |
529 |
530 |

531 | 532 | 533 | 534 | --------------------------------------------------------------------------------