ramplstilskin Posted August 24, 2017 Share Posted August 24, 2017 Hello friends. In my database I have table named "groups" and inside this table, among the others, I have column named "permissions" with a value {"admin": 1}. Now, in my PHP code, when I use json_decode function, nothing happens, function doesn't work and it won't print anything. This is my code: $group = $this->_db->get('groups', array('id', '=', $this->data()->protyp)); $permissions = json_decode($group->first()->permissions, true); print_r($permissions); When I echo $permissions = $group->first()->permissions; (without json_decode), everything works, but when I use json_decode, nothing happens. I use PHP 5.6. Can anyone help me? Thanks in advance Link to comment Share on other sites More sharing options...
requinix Posted August 24, 2017 Share Posted August 24, 2017 Apparently ->permissions is not the string you think it is. var_dump($group->first()->permissions); Link to comment Share on other sites More sharing options...
ginerjm Posted August 24, 2017 Share Posted August 24, 2017 Do you have php error checking turned on to help debug any possible errors? May I ask why you are storing data in your db in json format? Link to comment Share on other sites More sharing options...
ramplstilskin Posted August 24, 2017 Author Share Posted August 24, 2017 Do you have php error checking turned on to help debug any possible errors? May I ask why you are storing data in your db in json format? I am new to this, so I wanted to learn how to give admin rights this way where {"admin: 1"} means IS admin, and {"admin: 0"} means NOT admin, where, I gues, json_decode() should create an array, like this Array([admin] => 1). I saw a friend do it this way, but for some reason doesn't work for me. What is your suggestion, what is the best way to do it? Link to comment Share on other sites More sharing options...
ginerjm Posted August 24, 2017 Share Posted August 24, 2017 Read the manual. Read a book. Read a tutorial. Assign users a password and whatever security level you want in a specific 'users' table. Then when they sign in with a name and password you do a query to find that name and check if the (hashed) password in the table matches the hashed entry of a password they provide. If they succeed you now have their security level. PS - did you notice my signature by the way? Link to comment Share on other sites More sharing options...
ramplstilskin Posted August 24, 2017 Author Share Posted August 24, 2017 My God, problem was in typing mistake, it shouldn't be {"admin: 1"} but {"admin": 1}. So stupid mistake. Thanks for replys guys Link to comment Share on other sites More sharing options...
Jacques1 Posted August 24, 2017 Share Posted August 24, 2017 I'm afraid that assuming you've now solved the problem is even more stupid. Link to comment Share on other sites More sharing options...
ginerjm Posted August 24, 2017 Share Posted August 24, 2017 So - how will you handle things down the road if you need to give two types of permission to someone? Don't know who showed you this scheme, but it sure makes the whole process complicated. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.