Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote a PHP class that I use in all my projects that require different access for different roles. I put a copy of the class out on paste bin: <a href="http://pastebin.com/VubBkakb" rel="nofollow">class_role_restrictions.php</a>.</p> <p>This class also requires another class I wrote, which can be obtained here: <a href="http://pastebin.com/ATyzLUfK" rel="nofollow">better_mysqli.php</a></p> <p>The initial setup involves the creation of some database tables (The SQL create statements are found in comments at end of the class_role_restrictions.php file) and adding roles / user memberships via it's admin interface. </p> <p>Detailed setup/usage can be obtained here: <a href="http://pastebin.com/apfnSK8S" rel="nofollow">role_restrictions_detailed_example.php</a> </p> <p>Once it is setup you can use it like this:</p> <pre><code>&lt;?php include_once('class_role_restrictions.php'); include_once('better_mysqli.php'); $mysqli = new better_mysqli('your_server', 'your_user', 'your_pass', 'your_db_name'); if (mysqli_connect_errno()) { error_log(sprintf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error())); exit; } $role = new role_restrictions($mysqli, 'http://your_server.com/path/to/this/page/example.php'); // == Restrict an entire page to authorized users only == $role-&gt;restrict_to('role_name, to_restrict user_to', 'username_currently_logged_in'); // .. now do stuff that only users in any of the roles listed are allowed to do // -- OR -- // == Only do certain things if the username given is a member of any of the roles given == if( $role-&gt;has_role('a_list, of_roles, allowed', 'username_currently_logged_in') ){ // .. do stuff that only users in the given role(s) are allowed to do .. } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload