├── LICENCE
├── README.md
├── embedded_chat_demo.php
├── full_page_chat_demo.php
├── index.php
├── simple_chat
├── .htaccess
├── chat.php
├── css
│ ├── chat_emb.css
│ ├── chat_full.css
│ └── chat_global.css
├── includes
│ ├── chat_func.php
│ ├── core_func.php
│ ├── dbconnect.php
│ ├── markup_func.php
│ └── validation_func.php
├── index.php
├── init_chat.php
├── js
│ └── chat.js
├── login.php
├── login_form.php
├── logout.php
├── media
│ └── smilies
│ │ ├── biggrin.gif
│ │ ├── cool.gif
│ │ ├── mellow.gif
│ │ ├── ohmy.gif
│ │ ├── sad.gif
│ │ ├── smile.gif
│ │ ├── tongue.gif
│ │ └── wink.gif
├── recaptcha
│ ├── LICENSE
│ └── recaptchalib.php
├── register.php
└── register_form.php
└── sql
└── simple_chat.sql
/LICENCE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Manolis Agkopian
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Description:
2 | This is the **Simple Chat ;)**, a simple AJAX chat application written in PHP and Javascript with jQuery.
3 |
4 | The **Simple Chat ;)** comes in two different versions. The first, is the full-page version, where the chat window is placed inside your page content. The second is the embedded version, where the chat window is placed on a position-fixed bar, on the down-right side of the browser window. In the embedded version you can hide or show the chat window. A live demo of the **Simple Chat ;)** in both versions is available [here](http://magkopian.tk/simple-chat/).
5 |
6 | ## How to Use:
7 | To use the full page version of this chat application, please follow the steps that appear as comments inside the **full_page_chat_demo.php** file. To use the embedded version, follow the steps inside the **embedded_chat_demo.php** file.
8 |
9 | The **Simple Chat ;)** includes a basic register-login system. If your website already has a register-login system you have to modify the **init_chat.php** file. You have to replace the line `header('Location: simple_chat/login_form.php');` with a redirect to your own login page, also after a succesful login you have to set the `$_SESSION['uid']` variable with the id of the user.
10 |
11 | If you use the included login-register system you have to sign up for a Google's reCAPTCHA account in order to get an API key for the reCAPTCHA service and use it. After you get the API key modify the line `$privatekey = 'xxxxxxxxxxxxxxxxxxxx';` inside the function **validate_recaptcha** inside the file **validation_func.php** and the line `$publickey = 'xxxxxxxxxxxxxxxxxxxx'.'&hl=en';` inside the function **do_html_register_form** inside the file **markup_func.php**. If you don't want the reCAPTCHA at all, just remove the reCAPTCHA validation check inside the **register.php** script and modify the function **do_html_register_form** inside the **markup_func.php** file so it wont appear in the login form. Lastly for security reasons before you register any user, replace the salt string inside the **validate_password** function in the **validation_func.php** file.
12 |
13 | ## Database Setup:
14 |
15 | First inside your database you must have two tables. One named `message` and one named `user`.
16 |
17 | To create the `message` table run the following query:
18 |
19 | ```MYSQL
20 | CREATE TABLE IF NOT EXISTS `message` (
21 | `mid` int(10) unsigned NOT NULL AUTO_INCREMENT,
22 | `content` varchar(255) DEFAULT NULL,
23 | `uid` int(10) unsigned NOT NULL,
24 | `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
25 | PRIMARY KEY (`mid`),
26 | KEY `uid` (`uid`)
27 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
28 | ```
29 |
30 | To create `user` table run the following queries:
31 |
32 | ```MYSQL
33 | CREATE TABLE IF NOT EXISTS `user` (
34 | `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
35 | `uname` varchar(25) NOT NULL,
36 | `passwd` varchar(64) NOT NULL,
37 | PRIMARY KEY (`uid`),
38 | UNIQUE KEY `uname` (`uname`),
39 | KEY `passwd` (`passwd`)
40 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
41 |
42 |
43 | ALTER TABLE `message`
44 | ADD CONSTRAINT `message_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`);
45 | ```
46 |
47 | You can also just insert the **simple_chat.sql** file in your database.
48 |
49 | If you use your own login system and you have already a table with users but not named `user` the easier way to get around this, is to modify the file **chat_func.php**, and replace the `user` table name, with the one that you use, on the following lines:
50 |
51 | ```PHP
52 | $query = 'SELECT `mid`, `uname`, `content`, `time` FROM `user` INNER JOIN `message` ON `message`.`uid` = `user`.`uid` ORDER BY `time` DESC';
53 |
54 | $query = "SELECT `mid`, `uname`, `content`, `time` FROM `user` INNER JOIN `message` ON `message`.`uid` = `user`.`uid` WHERE `time` > '$timestamp'";
55 | ```
56 |
57 | Also you have to make sure that the table has all the needed fields in the correct format, except the `passwd` field that is handled by your own login-register scripts. If for some reason this is impossible to do, the only way is to create a second table named `user` with all the needed fields and make a duplicate of your users there, you have also to modify your registration script in order for it to register your users on both tables.
58 |
59 | If now your user table is named `user` you just have to make sure that it has the needed fields. If it doesn't, and also impossible to alter, the only way is ether to create a second database for the whole application and duplicate your users inside the `user` table, or create a table for the users with an other name within the same database and duplicate your user there. In the last case don't forget to modify the queries inside **chat_func.php**.
60 |
61 | Lastly but not least you have to modify the line `$con = @mysqli_connect('hostname', 'username', 'password', 'dbname');` inside the dbconnect.php file to match your own database setup.
62 |
63 | ## Licensing
64 |
65 | My code is licensed under the MIT Licence, please check the LICENCE file for copying permission. Please note that I do not own any of the code inside the recaptchalib.php file, please check the LICENSE file inside the /simple_chat/recaptcha directory. Also I do not own any of the smileys inside the smileys folder. All the smileys are provided free by [freesmileys.org](http://www.freesmileys.org).
66 |
--------------------------------------------------------------------------------
/embedded_chat_demo.php:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
79 | This is the embedded version of the Simple Chat. If you are logged in, the chat window should have been appeared on the right-bottom corner of your browser window.
80 | If you want to login, you can click here, or click here to register if you don't have an account.
81 |
82 |
83 |
Just some random text...
84 |
85 |
Am if number no up period regard sudden better. Decisively surrounded all admiration and not you. Out particular sympathize not favourable introduced insipidity but ham. Rather number can and set praise. Distrusts an it contented perceived attending oh. Thoroughly estimating introduced stimulated why but motionless.
86 |
87 |
At every tiled on ye defer do. No attention suspected oh difficult. Fond his say old meet cold find come whom. The sir park sake bred. Wonder matter now can estate esteem assure fat roused. Am performed on existence as discourse is. Pleasure friendly at marriage blessing or.
88 |
89 |
As am hastily invited settled at limited civilly fortune me. Really spring in extent an by. Judge but built gay party world. Of so am he remember although required. Bachelor unpacked be advanced at. Confined in declared marianne is vicinity.
90 |
91 |
Was justice improve age article between. No projection as up preference reasonably delightful celebrated. Preserved and abilities assurance tolerably breakfast use saw. And painted letters forming far village elderly compact. Her rest west each spot his and you knew. Estate gay wooded depart six far her. Of we be have it lose gate bred. Do separate removing or expenses in. Had covered but evident chapter matters anxious.
92 |
93 |
Two exquisite objection delighted deficient yet its contained. Cordial because are account evident its subject but eat. Can properly followed learning prepared you doubtful yet him. Over many our good lady feet ask that. Expenses own moderate day fat trifling stronger sir domestic feelings. Itself at be answer always exeter up do. Though or my plenty uneasy do. Friendship so considered remarkably be to sentiments. Offered mention greater fifteen one promise because nor. Why denoting speaking fat indulged saw dwelling raillery.
94 |
95 |
Inquietude simplicity terminated she compliment remarkably few her nay. The weeks are ham asked jokes. Neglected perceived shy nay concluded. Not mile draw plan snug next all. Houses latter an valley be indeed wished merely in my. Money doubt oh drawn every or an china. Visited out friends for expense message set eat.
96 |
97 |
Enjoyed minutes related as at on on. Is fanny dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.
98 |
99 |
Guest it he tears aware as. Make my no cold of need. He been past in by my hard. Warmly thrown oh he common future. Otherwise concealed favourite frankness on be at dashwoods defective at. Sympathize interested simplicity at do projecting increasing terminated. As edward settle limits at in.
100 |
101 |
Yourself off its pleasant ecstatic now law. Ye their mirth seems of songs. Prospect out bed contempt separate. Her inquietude our shy yet sentiments collecting. Cottage fat beloved himself arrived old. Grave widow hours among him no you led. Power had these met least nor young. Yet match drift wrong his our.
102 |
103 |
Was justice improve age article between. No projection as up preference reasonably delightful celebrated. Preserved and abilities assurance tolerably breakfast use saw. And painted letters forming far village elderly compact. Her rest west each spot his and you knew. Estate gay wooded depart six far her. Of we be have it lose gate bred. Do separate removing or expenses in. Had covered but evident chapter matters anxious.
104 |
105 |
Two exquisite objection delighted deficient yet its contained. Cordial because are account evident its subject but eat. Can properly followed learning prepared you doubtful yet him. Over many our good lady feet ask that. Expenses own moderate day fat trifling stronger sir domestic feelings. Itself at be answer always exeter up do. Though or my plenty uneasy do. Friendship so considered remarkably be to sentiments. Offered mention greater fifteen one promise because nor. Why denoting speaking fat indulged saw dwelling raillery.
106 |
107 |
Inquietude simplicity terminated she compliment remarkably few her nay. The weeks are ham asked jokes. Neglected perceived shy nay concluded. Not mile draw plan snug next all. Houses latter an valley be indeed wished merely in my. Money doubt oh drawn every or an china. Visited out friends for expense message set eat.
108 |
109 |
Enjoyed minutes related as at on on. Is fanny dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.
110 |
111 |
Was justice improve age article between. No projection as up preference reasonably delightful celebrated. Preserved and abilities assurance tolerably breakfast use saw. And painted letters forming far village elderly compact. Her rest west each spot his and you knew. Estate gay wooded depart six far her. Of we be have it lose gate bred. Do separate removing or expenses in. Had covered but evident chapter matters anxious.
112 |
113 |
Two exquisite objection delighted deficient yet its contained. Cordial because are account evident its subject but eat. Can properly followed learning prepared you doubtful yet him. Over many our good lady feet ask that. Expenses own moderate day fat trifling stronger sir domestic feelings. Itself at be answer always exeter up do. Though or my plenty uneasy do. Friendship so considered remarkably be to sentiments. Offered mention greater fifteen one promise because nor. Why denoting speaking fat indulged saw dwelling raillery.
114 |
115 |
Inquietude simplicity terminated she compliment remarkably few her nay. The weeks are ham asked jokes. Neglected perceived shy nay concluded. Not mile draw plan snug next all. Houses latter an valley be indeed wished merely in my. Money doubt oh drawn every or an china. Visited out friends for expense message set eat.
116 |
117 |
Enjoyed minutes related as at on on. Is fanny dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.
118 |
119 |
Was justice improve age article between. No projection as up preference reasonably delightful celebrated. Preserved and abilities assurance tolerably breakfast use saw. And painted letters forming far village elderly compact. Her rest west each spot his and you knew. Estate gay wooded depart six far her. Of we be have it lose gate bred. Do separate removing or expenses in. Had covered but evident chapter matters anxious.
120 |
121 |
Two exquisite objection delighted deficient yet its contained. Cordial because are account evident its subject but eat. Can properly followed learning prepared you doubtful yet him. Over many our good lady feet ask that. Expenses own moderate day fat trifling stronger sir domestic feelings. Itself at be answer always exeter up do. Though or my plenty uneasy do. Friendship so considered remarkably be to sentiments. Offered mention greater fifteen one promise because nor. Why denoting speaking fat indulged saw dwelling raillery.
122 |
123 |
Inquietude simplicity terminated she compliment remarkably few her nay. The weeks are ham asked jokes. Neglected perceived shy nay concluded. Not mile draw plan snug next all. Houses latter an valley be indeed wished merely in my. Money doubt oh drawn every or an china. Visited out friends for expense message set eat.
124 |
125 |
Enjoyed minutes related as at on on. Is fanny dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.
126 |
127 |
Was justice improve age article between. No projection as up preference reasonably delightful celebrated. Preserved and abilities assurance tolerably breakfast use saw. And painted letters forming far village elderly compact. Her rest west each spot his and you knew. Estate gay wooded depart six far her. Of we be have it lose gate bred. Do separate removing or expenses in. Had covered but evident chapter matters anxious.
128 |
129 |
Two exquisite objection delighted deficient yet its contained. Cordial because are account evident its subject but eat. Can properly followed learning prepared you doubtful yet him. Over many our good lady feet ask that. Expenses own moderate day fat trifling stronger sir domestic feelings. Itself at be answer always exeter up do. Though or my plenty uneasy do. Friendship so considered remarkably be to sentiments. Offered mention greater fifteen one promise because nor. Why denoting speaking fat indulged saw dwelling raillery.
130 |
131 |
Inquietude simplicity terminated she compliment remarkably few her nay. The weeks are ham asked jokes. Neglected perceived shy nay concluded. Not mile draw plan snug next all. Houses latter an valley be indeed wished merely in my. Money doubt oh drawn every or an china. Visited out friends for expense message set eat.
132 |
133 |
Enjoyed minutes related as at on on. Is fanny dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.
';
71 |
72 | if ($i == 0) { //get the timestamp of the last message
73 | $lastmsg_timestamp = $msg['time'];
74 | }
75 | }
76 |
77 | return array('messages_content' => $messages, 'lastmsg_timestamp' => $lastmsg_timestamp); //return the messages formated + the timestamp of the last one
78 | }
79 |
80 | //pushes one message into the database
81 | function push_message ($msg) {
82 | $uid = get_user_id();
83 |
84 | //connect to the database
85 | $con = db_connect();
86 | if ($con === false) {
87 | return false;
88 | }
89 |
90 | //sanitize the message
91 | $msg = mysqli_real_escape_string($con, $msg);
92 |
93 | //push a message into the database
94 | $query = "INSERT INTO `message` (`content`, `uid`) VALUES('$msg', $uid)";
95 | $res = mysqli_query($con, $query);
96 |
97 | if ($res === false || mysqli_affected_rows($con) != 1) {
98 | mysqli_close($con); //close the database
99 | return false;
100 | }
101 | mysqli_close($con); //close the database
102 |
103 | return true;
104 | }
105 |
106 | function add_smileys ($msg) {
107 | /*
108 | * Please note that I am not the owner of any of the smilie icons that I use in this project.
109 | * All the smilie icons that I use, are provided free by www.freesmileys.org.
110 | * If you don't like the icons that I included or you want to add more,
111 | * you can use your own or download more from www.freesmileys.org.
112 | */
113 |
114 | //To add an new smilie, first register it in the following array
115 | //and then put an 20px X 20px image of it in the media/smilies directory.
116 | //The image type must be GIF and the name must be the same with its value
117 | //in the following array, e.g. 'cool.gif'.
118 | $smilies = array(
119 | ':|' => 'mellow',
120 | ':-|' => 'mellow',
121 | ':-o' => 'ohmy',
122 | ':-O' => 'ohmy',
123 | ':o' => 'ohmy',
124 | ':O' => 'ohmy',
125 | ';)' => 'wink',
126 | ';-)' => 'wink',
127 | ':p' => 'tongue',
128 | ':-p' => 'tongue',
129 | ':P' => 'tongue',
130 | ':-P' => 'tongue',
131 | ':D' => 'biggrin',
132 | ':-D' => 'biggrin',
133 | '8)' => 'cool',
134 | '8-)' => 'cool',
135 | ':)' => 'smile',
136 | ':-)' => 'smile',
137 | ':(' => 'sad',
138 | ':-(' => 'sad'
139 | );
140 |
141 | //search and replace any ascii smilie with an image tag
142 | foreach ($smilies as $smilie => $image) {
143 | $regex = preg_quote("/$smilie/");
144 | $image_tag = '';
145 |
146 | $msg = preg_replace($regex, $image_tag, $msg);
147 | }
148 |
149 | return $msg;
150 | }
151 | ?>
--------------------------------------------------------------------------------
/simple_chat/includes/core_func.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/simple_chat/includes/dbconnect.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/simple_chat/includes/markup_func.php:
--------------------------------------------------------------------------------
1 |
16 |
17 | To view the chat window on this page you have to be logged in, please click here to login.
18 |