PHP API
| Introduction This guide assumes that you have atleast basic knowledge of PHP. To use this API, you must include the plugins.php file from the cometchat folder. sendMessageTo() function This function allows you to send a message from the logged in user to another user.
sendMessageTo('USERID','MESSAGE');
For example, if you would like to send a Hello world! message to user with USERID 1
sendMessageTo('1','Hello world!');
Note: If you are accepting input from user for the contents of the message, make sure that you filter the input. Do NOT addSlashes or escape the string, as CometChat will automatically do that for you. For sanitizing the input, you can use CometChat's in-built function:
sendMessageTo('1',sanitize('Hello world!'));
sendSelfMessage() function This function allows you to send a message to the logged in user from the himself/herself. This function is used to provide feedback to the user. For example if the user sends a file to another user, you would like to provide a feedback to the user- "has sent a file successfully".
sendSelfMessage('USERID','MESSAGE');
Here USERID is not that of the logged in user but the USERID of the user in which the chat conversation is taking place. For example, if you would like to send a has sent hello world message to user who is chatting with user USERID 1
sendSelfMessage('1','has sent hello world!');
Note: If you are accepting input from user for the contents of the message, make sure that you filter the input. Do NOT addSlashes or escape the string, as CometChat will automatically do that for you. For sanitizing the input, you can use CometChat's in-built function:
sendSelfMessage('1',sanitize('has sent hello world!'));
Global variables Globally accessible variables are as follows: $userid // The USERID of the logged in user. 0 if not logged in $theme // Current selected theme Global constants Globally accessible constants are as follows: BASE_URL // The path to the cometchat folder (with trailing slash) TABLE_PREFIX // Prefix to the users table DB_USERTABLE // Use in conjunction with TABLE_PREFIX DB_USERTABLE_NAME // The username/display name field DB_USERTABLE_USERID // The userid field |



