Skip to content
Advertisement

PHP: unserialize(): Error at offset 757 of 784 bytes

why does it return an “unserialize(): Error at offset 757 of 784 bytes” i was just adding permission to the serialized string in the database here is my string

database: permission row

Super Admin:

a:32:{i:0;s:10:"createUser";i:1;s:10:"updateUser";i:2;s:8:"viewUser";i:3;s:10:"deleteUser";i:4;s:11:"createGroup";i:5;s:11:"updateGroup";i:6;s:9:"viewGroup";i:7;s:11:"deleteGroup";i:8;s:11:"createStore";i:9;s:11:"updateStore";i:10;s:9:"viewStore";i:11;s:11:"deleteStore";i:12;s:11:"createTable";i:13;s:11:"updateTable";i:14;s:9:"viewTable";i:15;s:11:"deleteTable";i:16;s:14:"createCategory";i:17;s:14:"updateCategory";i:18;s:12:"viewCategory";i:19;s:14:"deleteCategory";i:20;s:13:"createProduct";i:21;s:13:"updateProduct";i:22;s:11:"viewProduct";i:23;s:13:"deleteProduct";i:24;s:11:"createOrder";i:25;s:11:"updateOrder";i:26;s:9:"viewOrder";i:27;s:11:"deleteOrder";i:28;s:10:"viewReport";i:29;s:13:"updateCompany";i:30;s:11:"viewProfile";i:31;s:13:"updateSetting";}

Cashier:

a:10:{i:0;s:8:"viewFile";i:1;s:9:"viewStore";i:2;s:11:"updateTable";i:3;s:9:"viewTable";i:4;s:11:"createOrder";i:5;s:11:"updateOrder";i:6;s:9:"viewOrder";i:7;s:11:"deleteOrder";i:8;s:10:"viewReport";i:9;s:11:"viewProfile";}

Manager:

a:20:{i:0;s:8:"viewFile";i:1;s:8:"viewUser";i:2;s:11:"createGroup";i:3;s:11:"updateGroup";i:4;s:9:"viewGroup";i:5;s:11:"deleteGroup";i:6;s:9:"viewStore";i:7;s:11:"createTable";i:8;s:11:"updateTable";i:9;s:9:"viewTable";i:10;s:11:"deleteTable";i:11;s:14:"updateCategory";i:12;s:13:"createProduct";i:13;s:13:"updateProduct";i:14;s:11:"viewProduct";i:15;s:13:"deleteProduct";i:16;s:9:"viewOrder";i:17;s:11:"deleteOrder";i:18;s:10:"viewReport";i:19;s:11:"viewProfile";}

My_controller.php:

$group_data = array();
if(empty($this->session->userdata('logged_in'))) {
    $session_data = array('logged_in' => FALSE);
    $this->session->set_userdata($session_data);
}
else {
    $user_id = $this->session->userdata('id');
    $this->load->model('model_groups');
    $group_data = $this->model_groups->getUserGroupByUserId($user_id);
    
    $this->data['user_permission'] = unserialize($group_data['permission']);

    $this->permission = unserialize($group_data['permission']);
}

as you can see there was an i:0;s:8:”viewFile”; in the cashier and the manager and in my web you cannot manipulate the super admin permission, so i try the manual in the localhost phpmyadmin i add the line “i:0;s:8:”viewFile”;” just like in the cashier and manager and then i got the “unserialize(): Error at offset 757 of 784 bytes”. what seems the error here and how can i manipulate the super admin permission.

Advertisement

Answer

You also have to increment the array count at the beginning of the string from 32 to 33 because you are adding another occurance.

So the Super Admin started as

a:32:{i:0;s:10:"createUser"; . . . 

and when you add another occurance to the array you must increment 32 into 33

a:33:{i:0;s:8:"viewFile";i:0;s:10:"createUser"; . . . 
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement