Jump to content

json_decode won't work


ramplstilskin

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.