Retrieving Chat messages between two users with Codeigniter |
Hi
I implemented a chat system using Codeigniter where users can send and receive chat messages but the problem I'm having is that everyone can see everyone's chat. How can I make the chat messages only accessible to the sender and receiver/recipient and vice versa? Controller - Chat.php Code: public function ajax_get_chat_messages(){ [b]Model - Chat_model.php[/b] Code: public function get_chat_messages($chat_id, $last_chat_message_id = 0){ [b][b]js - chat.js[/b][/b] Code: function get_chat_messages()
Send the user id along with it and check it if that's not the user do not send it to them.
User 1 chats with User 4 User 4 can only see messages from User 1 and vise versa. Sessions would be great for this. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(11-07-2017, 10:10 AM)InsiteFX Wrote: Send the user id along with it and check it if that's not the user do not send it to them. Hi InsiteFX, Thanks for the feedback. Would hat be in the where clause of my query? The logic is what I imagined bu for some reason I cant really get i right. Please see a screenshot of my table. Thank you.
Your storing the chat_id and user_id so you can use those.
If chat_id is the user_id of the person that started the chat and then the user_id is the one that they are chatting with then you can check those. If it was me I would have a method called intiateChat() that would set this all up for checking later. Without seeing some of your code it is hard to see what you are trying to do. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |