├── 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 | 14 | Simple Chat | Embedded Version Demo 15 | 16 | 17 | 18 | 19 | 62 | 63 | 64 | 65 | 66 | 67 |
68 |

Simple Chat ;)

69 | 70 | 71 | 77 | 78 |

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.

134 | 135 | 136 | 137 |
138 | 139 | -------------------------------------------------------------------------------- /full_page_chat_demo.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | Simple Chat | Full Page Version Demo 16 | 17 | 18 | 19 | 20 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |

Simple Chat ;)

68 | 69 | 70 | 76 | 77 | 78 | 79 |
80 | 81 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | Simple Chat 11 | 12 | 13 | 14 | 15 | 50 | 51 | 52 |
53 |

Simple Chat ;)

54 | 55 |
56 |

This a Simple Chat System using PHP & Ajax. Please choose a demo page from below to try it:

57 | Embedded Chat Version - Demo 58 | Full Page Chat Version - Demo 59 |
60 |
61 | 62 | -------------------------------------------------------------------------------- /simple_chat/.htaccess: -------------------------------------------------------------------------------- 1 | #Copyright (c) 2013 Manolis Agkopian 2 | #See the file LICENCE for copying permission. 3 | 4 | Options -Indexes -------------------------------------------------------------------------------- /simple_chat/chat.php: -------------------------------------------------------------------------------- 1 | 1, 31 | 'status_msg' => 'The messages cannot be loaded cause of an error.', //database error 32 | ); 33 | 34 | header('Content-type: application/json'); 35 | echo json_encode($response); //send the server responce as a json object 36 | die(); //messages has been loaded successfully 37 | 38 | } 39 | else { 40 | 41 | $response = array( 42 | 'msg' => $messages['messages_content'], 43 | 'status_code' => 0, 44 | 'status_msg' => 'SUCCESS', 45 | 'timestamp' => $messages['lastmsg_timestamp'] 46 | ); 47 | 48 | header('Content-type: application/json'); 49 | echo json_encode($response); //send the server responce as a json object 50 | die(); //messages has been loaded successfully 51 | 52 | } 53 | } 54 | else if ($_POST['method'] == 'push_message') { //or push a message to the database 55 | if (isset($_POST['msg']) && !empty($_POST['msg'])) { 56 | $_POST['msg'] = trim($_POST['msg']); 57 | 58 | if (validate_len($_POST['msg'], 255) === false) { //if the user submited more than 255 characters 59 | $response = array( 60 | 'status_code' => 3, 61 | 'status_msg' => 'The message must be max 255 characters long.' 62 | ); 63 | 64 | header('Content-type: application/json'); 65 | echo json_encode($response); //send the server responce as a json object 66 | die(); //messages has been loaded successfully 67 | } 68 | else if (push_message($_POST['msg']) === false) { 69 | $response = array( 70 | 'status_code' => 2, 71 | 'status_msg' => 'The message cannot be submitted cause of an error.' //database error 72 | ); 73 | 74 | header('Content-type: application/json'); 75 | echo json_encode($response); //send the server responce as a json object 76 | die(); //messages has been loaded successfully 77 | } 78 | else { 79 | $response = array( 80 | 'status_code' => 0, 81 | 'status_msg' => 'SUCCESS' 82 | ); 83 | 84 | header('Content-type: application/json'); 85 | echo json_encode($response); //send the server responce as a json object 86 | die(); //the messages submitted successfully 87 | } 88 | } 89 | } 90 | } 91 | 92 | //if none of the above statements have been executed 93 | header('HTTP/1.1 403 Forbidden'); //then the POST variables are not valid so throw a 403 error 94 | do_html_403(); 95 | die(); 96 | ?> -------------------------------------------------------------------------------- /simple_chat/css/chat_emb.css: -------------------------------------------------------------------------------- 1 | /**********************************************\ 2 | * Copyright (c) 2013 Manolis Agkopian * 3 | * See the file LICENCE for copying permission. * 4 | \**********************************************/ 5 | 6 | #chat { 7 | position: fixed; 8 | bottom: 30px; 9 | right: 25px; 10 | } 11 | 12 | #bar { 13 | position: fixed; 14 | bottom: 0; 15 | left: 0; 16 | width: 100%; 17 | height: 25px; 18 | background-color: #AAA; 19 | } 20 | 21 | #toggle_chat { 22 | width: 204px; 23 | height: 25px; 24 | background-color: slategray; 25 | position: absolute; 26 | right: 21px; 27 | } 28 | 29 | #toggle_chat p { 30 | color: #FFF; 31 | margin: 0 auto; 32 | font-weight: bold; 33 | text-align: center; 34 | 35 | -webkit-user-select: none; /* Chrome/Safari */ 36 | -moz-user-select: none; /* Firefox */ 37 | -ms-user-select: none; /* IE10+ */ 38 | 39 | /* Rules below not implemented in browsers yet */ 40 | -o-user-select: none; 41 | user-select: none; 42 | 43 | cursor: pointer; 44 | } 45 | 46 | #chat { 47 | width: 200px; 48 | height: 305px; 49 | margin: 0; 50 | padding: 0; 51 | } 52 | 53 | #messages { 54 | width: 180px; 55 | padding: 0; 56 | padding: 2px; 57 | margin: 0; 58 | word-wrap: break-word; 59 | background-color: #FEFEFE; 60 | } 61 | 62 | #msg_cont { 63 | width: 200px; 64 | height: 244px; 65 | border: 1px solid #CCC; 66 | padding: 0; 67 | padding: 2px; 68 | margin: 0; 69 | overflow-y: hidden; 70 | overflow-x: hidden; 71 | word-wrap: break-word; 72 | background-color: #FEFEFE; 73 | } 74 | 75 | #msg_cont:hover { 76 | overflow-y: scroll; 77 | } 78 | 79 | #input_msg { 80 | width: 100%; 81 | height: 50px; 82 | margin: 0; 83 | padding: 0; 84 | } 85 | 86 | #msg { 87 | width: 100%; 88 | height: 50px; 89 | margin: 0; 90 | padding: 0; 91 | background-color: #FEFEFE; 92 | resize: none; 93 | border: 2px inset #DDD; 94 | } 95 | 96 | #logout { 97 | background-color: slategray; 98 | display: inline-block; 99 | height: 25px; 100 | text-decoration: none; 101 | font-weight: bold; 102 | width: 80px; 103 | text-align: center; 104 | color: #FFF; 105 | } 106 | 107 | #logout span, #toggle_chat p span{ 108 | vertical-align: middle; 109 | } 110 | 111 | .message { 112 | padding: 0 5px; 113 | margin-bottom: 10px; 114 | } 115 | .message p{ 116 | margin: 0; 117 | } 118 | 119 | .time { 120 | font-size: 12px; 121 | color: slategray; 122 | } 123 | 124 | .error { 125 | color: red; 126 | margin: 5px 0; 127 | } 128 | 129 | .smilie { 130 | width: 20px; 131 | height: 20px; 132 | vertical-align:middle 133 | } 134 | -------------------------------------------------------------------------------- /simple_chat/css/chat_full.css: -------------------------------------------------------------------------------- 1 | /**********************************************\ 2 | * Copyright (c) 2013 Manolis Agkopian * 3 | * See the file LICENCE for copying permission. * 4 | \**********************************************/ 5 | 6 | #chat { 7 | width: 100%; 8 | height: 505px; 9 | } 10 | 11 | #messages { 12 | width: 100%; 13 | height: 393px; 14 | border: 1px solid #EEE; 15 | padding: 2px; 16 | margin-bottom: 5px; 17 | overflow-y: scroll; 18 | overflow-x: hidden; 19 | word-wrap: break-word; 20 | } 21 | 22 | #input_msg { 23 | width: 100%; 24 | height: 100px; 25 | } 26 | 27 | #msg { 28 | width: 100%; 29 | height: 100px; 30 | resize: none; 31 | } 32 | 33 | #logout a{ 34 | background-color: slategray; 35 | text-decoration: none; 36 | font-weight: bold; 37 | height: 25px; 38 | width: 80px; 39 | text-align: center; 40 | color: #FFF; 41 | float: right; 42 | margin-right: 15px; 43 | border-radius:25px; 44 | position: relative; 45 | top: 30px; 46 | } 47 | 48 | #logout a span{ 49 | vertical-align: middle; 50 | } 51 | 52 | .clear { 53 | clear: left; 54 | display: block; 55 | } 56 | 57 | .message { 58 | padding: 5px; 59 | margin-bottom: 5px; 60 | } 61 | .message p{ 62 | margin: 5px 0; 63 | } 64 | 65 | .time { 66 | font-size: 12px; 67 | color: slategray; 68 | } 69 | 70 | .error { 71 | color: red; 72 | margin: 5px 0; 73 | } 74 | 75 | .smilie { 76 | width: 20px; 77 | height: 20px; 78 | vertical-align:middle 79 | } 80 | -------------------------------------------------------------------------------- /simple_chat/css/chat_global.css: -------------------------------------------------------------------------------- 1 | /**********************************************\ 2 | * Copyright (c) 2013 Manolis Agkopian * 3 | * See the file LICENCE for copying permission. * 4 | \**********************************************/ 5 | 6 | body , div, img, p, h1{ 7 | font-family: arial; 8 | margin: 0; 9 | padding: 0; 10 | font-weight: normal; 11 | } 12 | 13 | #wrapper { 14 | width: 100%; 15 | margin: 15px auto; 16 | position: relative; 17 | } 18 | 19 | #title { 20 | margin: 5px auto; 21 | text-align: center; 22 | } 23 | 24 | #title h1 { 25 | white-space: nowrap; 26 | font-size: 40px; 27 | } 28 | 29 | .error { 30 | color: red; 31 | margin: 5px 0; 32 | } -------------------------------------------------------------------------------- /simple_chat/includes/chat_func.php: -------------------------------------------------------------------------------- 1 | '$timestamp' ORDER BY `time` DESC"; 36 | } 37 | 38 | $res = mysqli_query($con, $query); 39 | 40 | if ($res === false) { 41 | mysqli_close($con); //close the database 42 | return false; 43 | } 44 | else if (($msg_num = mysqli_affected_rows($con)) === 0) { //if nothing is returned 45 | mysqli_close($con); //close the database 46 | 47 | if ($timestamp === false) { 48 | $timestamp = '-1'; //if the database is empty, return -1 as a timestamp to the client 49 | $lastmsg_timestamp = '-1'; 50 | } 51 | else { 52 | $lastmsg_timestamp = $timestamp; //else if there are no new messages, return the last requested timestamp back 53 | } 54 | return array('messages_content' => '', 'lastmsg_timestamp' => $lastmsg_timestamp); //no messages to display, so return '' 55 | } 56 | mysqli_close($con); //close the database 57 | 58 | //if there are new messages available 59 | 60 | //format the messages 61 | $messages = ''; 62 | 63 | for ($i = 0; $i < $msg_num; ++$i) { 64 | $msg = mysqli_fetch_assoc($res); 65 | 66 | $messages .= 67 | '
68 | ('.$msg['time'].') '.htmlentities($msg['uname'], ENT_QUOTES, 'UTF-8').' says: 69 |

'.add_smileys(nl2br(htmlentities($msg['content'], ENT_QUOTES, 'UTF-8'))).'

70 |
'; 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 = ''.$smilie.''; 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 |

19 | 25 |

Click to Hide

Logout
26 | 29 |
30 |
31 |

32 |
33 | 34 | 36 |
Logout
37 |
38 | 41 | 42 |
43 |
44 | 45 |
46 |
47 | 48 |
49 | 50 |
51 |
52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 403 Forbidden 63 | 64 | 65 | 66 |

403 Forbidden

67 |

You don't have permission to access on this server.

68 | 69 | 70 | 74 | 79 |
80 | '.$errors['uname'].'

' : ''?> 81 | 82 | 83 | '.$errors['passwd'].'

' : ''?> 84 | 85 | 86 | 87 | 88 |
89 | 93 | 98 |
99 | '.$errors['uname'].'

' : ''?> 100 | 101 | 102 | '.$errors['passwd'].'

' : ''?> 103 | 104 | 105 | ', $errors['recaptcha'], '

'; 108 | } 109 | 110 | require 'recaptcha/recaptchalib.php'; 111 | $publickey = 'xxxxxxxxxxxxxxxxxxxx'.'&hl=en'; 112 | echo recaptcha_get_html($publickey); 113 | ?> 114 | 115 | 116 | 117 |
118 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /simple_chat/includes/validation_func.php: -------------------------------------------------------------------------------- 1 | is_valid) { 41 | return false; 42 | } 43 | return true; 44 | } 45 | 46 | function validate_timestamp ($timestamp) { 47 | //check the format of the mysql timestamp with a regex 48 | $regex = '/^([1-9][0-9]*)-(([0][1-9])|([1][0-2]))-(([0][1-9])|([12][0-9])|([3][01]))[\s](([01][0-9])|([2][0-3]))[:](([0-5][0-9]))[:](([0-5][0-9]))$/'; 49 | if (preg_match($regex, $timestamp, $matches) === false) { 50 | return false; 51 | } 52 | 53 | //check if the numbers are represent a valid date 54 | return date('Y-m-d H:i:s', mktime($matches[9], $matches[12], $matches[14], $matches[2], $matches[5], $matches[1])); 55 | } 56 | 57 | function validate_len ($str, $max_len, $min_len = 1) { 58 | if ($max_len !== 'inf') { 59 | if (mb_strlen($str, 'UTF-8') > $max_len || mb_strlen($str, 'UTF-8') < $min_len) { 60 | return false; 61 | } 62 | } 63 | else { 64 | if (mb_strlen($str, 'UTF-8') < $min_len) { 65 | return false; 66 | } 67 | } 68 | return true; 69 | } 70 | ?> -------------------------------------------------------------------------------- /simple_chat/index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_chat/init_chat.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_chat/js/chat.js: -------------------------------------------------------------------------------- 1 | /**********************************************\ 2 | * Copyright (c) 2013 Manolis Agkopian * 3 | * See the file LICENCE for copying permission. * 4 | \**********************************************/ 5 | 6 | var chat = {} 7 | 8 | chat.get_messages = function () { 9 | $.ajax({ 10 | url: 'simple_chat/chat.php', 11 | type: 'post', 12 | dataType: 'json', 13 | data: {method: 'get_messages', timestamp: chat.lastmsg_timestamp}, 14 | success: function (data) { 15 | if (data.status_code != 0) { //if there was an error 16 | $('#errors_box .error').html(data.status_msg); //set the errors_box 17 | } 18 | else { 19 | $('#messages').prepend(data.msg); //else print the messages 20 | chat.lastmsg_timestamp = data.timestamp; //update the last message timestamp, so the next time we will ask only for the new messages 21 | } 22 | } 23 | }); 24 | } 25 | 26 | $('#msg').keypress(function(event) { 27 | //check if user have press enter without shift 28 | if (event.keyCode == 13 && event.shiftKey == false) { 29 | chat.msg_contents = $('#msg').val(); //get the value of the textarea 30 | 31 | $.ajax({ //push the message using ajax to the server 32 | url: 'simple_chat/chat.php', 33 | type: 'post', 34 | dataType: 'json', 35 | data: {method: 'push_message', msg: chat.msg_contents, timestamp: chat.lastmsg_timestamp}, 36 | success: function (data) { 37 | if (data.status_code != 0) { //if there was an error 38 | $('#errors_box .error').html(data.status_msg); //set the errors_box 39 | } 40 | else { 41 | chat.get_messages(); //else, after the push immediately refresh the messages 42 | $('#errors_box .error').html(''); //clear last error message 43 | } 44 | } 45 | }); 46 | 47 | 48 | $('#msg').val(''); //clear the form 49 | return false; //and don't allow the new line to be printed 50 | } 51 | }); 52 | 53 | //this is for the embedded chat version only 54 | var chat_state = 0; 55 | $('#toggle_chat').click(function () { 56 | $('#chat').slideToggle(function () { 57 | if (chat_state == 1) { 58 | $('#toggle_chat p').html('Click to Hide'); 59 | chat_state = 0; 60 | } 61 | else { 62 | $('#toggle_chat p').html('Click to Unhide'); 63 | chat_state = 1; 64 | } 65 | }); 66 | }); 67 | 68 | chat.interval = setInterval(chat.get_messages, 5000); //the chat will be updated every 5 seconds 69 | chat.lastmsg_timestamp = '-1'; //if the page is reloaded fetch all the messages at once, to do that we set timestamp to -1 70 | chat.get_messages(); //when page is loaded get the messages immediately -------------------------------------------------------------------------------- /simple_chat/login.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_chat/login_form.php: -------------------------------------------------------------------------------- 1 | You have been registered successfully! You can now login.

'; 25 | } 26 | 27 | $errors = array(); 28 | if (isset($_SESSION['login_errors']) && !empty($_SESSION['login_errors'])) { 29 | $errors = $_SESSION['login_errors']; 30 | unset($_SESSION['login_errors']); 31 | } 32 | ?> 33 | 34 | 35 | 36 | Login Form 37 | 38 | 39 | 75 | 76 | 77 |
78 |
79 |
80 |

Login Form

81 |
82 | 83 | 84 |
85 |
86 | 87 | -------------------------------------------------------------------------------- /simple_chat/logout.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_chat/media/smilies/biggrin.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/biggrin.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/cool.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/cool.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/mellow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/mellow.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/ohmy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/ohmy.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/sad.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/sad.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/smile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/smile.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/tongue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/tongue.gif -------------------------------------------------------------------------------- /simple_chat/media/smilies/wink.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magkopian/php-ajax-simple-chat/570ad61d92a61d02791b0c01b60404e4a6a01eaf/simple_chat/media/smilies/wink.gif -------------------------------------------------------------------------------- /simple_chat/recaptcha/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net 2 | AUTHORS: 3 | Mike Crawford 4 | Ben Maurer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be INCLUDED in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /simple_chat/recaptcha/recaptchalib.php: -------------------------------------------------------------------------------- 1 | $value ) 50 | $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; 51 | 52 | // Cut the last '&' 53 | $req=substr($req,0,strlen($req)-1); 54 | return $req; 55 | } 56 | 57 | 58 | 59 | /** 60 | * Submits an HTTP POST to a reCAPTCHA server 61 | * @param string $host 62 | * @param string $path 63 | * @param array $data 64 | * @param int port 65 | * @return array response 66 | */ 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { 68 | 69 | $req = _recaptcha_qsencode ($data); 70 | 71 | $http_request = "POST $path HTTP/1.0\r\n"; 72 | $http_request .= "Host: $host\r\n"; 73 | $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; 74 | $http_request .= "Content-Length: " . strlen($req) . "\r\n"; 75 | $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; 76 | $http_request .= "\r\n"; 77 | $http_request .= $req; 78 | 79 | $response = ''; 80 | if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { 81 | die ('Could not open socket'); 82 | } 83 | 84 | fwrite($fs, $http_request); 85 | 86 | while ( !feof($fs) ) 87 | $response .= fgets($fs, 1160); // One TCP-IP packet 88 | fclose($fs); 89 | $response = explode("\r\n\r\n", $response, 2); 90 | 91 | return $response; 92 | } 93 | 94 | 95 | 96 | /** 97 | * Gets the challenge HTML (javascript and non-javascript version). 98 | * This is called from the browser, and the resulting reCAPTCHA HTML widget 99 | * is embedded within the HTML form it was called from. 100 | * @param string $pubkey A public key for reCAPTCHA 101 | * @param string $error The error given by reCAPTCHA (optional, default is null) 102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) 103 | 104 | * @return string - The HTML to be embedded in the user's form. 105 | */ 106 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) 107 | { 108 | if ($pubkey == null || $pubkey == '') { 109 | die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); 110 | } 111 | 112 | if ($use_ssl) { 113 | $server = RECAPTCHA_API_SECURE_SERVER; 114 | } else { 115 | $server = RECAPTCHA_API_SERVER; 116 | } 117 | 118 | $errorpart = ""; 119 | if ($error) { 120 | $errorpart = "&error=" . $error; 121 | } 122 | return ' 123 | 124 | '; 129 | } 130 | 131 | 132 | 133 | 134 | /** 135 | * A ReCaptchaResponse is returned from recaptcha_check_answer() 136 | */ 137 | class ReCaptchaResponse { 138 | var $is_valid; 139 | var $error; 140 | } 141 | 142 | 143 | /** 144 | * Calls an HTTP POST function to verify if the user's guess was correct 145 | * @param string $privkey 146 | * @param string $remoteip 147 | * @param string $challenge 148 | * @param string $response 149 | * @param array $extra_params an array of extra variables to post to the server 150 | * @return ReCaptchaResponse 151 | */ 152 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) 153 | { 154 | if ($privkey == null || $privkey == '') { 155 | die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); 156 | } 157 | 158 | if ($remoteip == null || $remoteip == '') { 159 | die ("For security reasons, you must pass the remote ip to reCAPTCHA"); 160 | } 161 | 162 | 163 | 164 | //discard spam submissions 165 | if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { 166 | $recaptcha_response = new ReCaptchaResponse(); 167 | $recaptcha_response->is_valid = false; 168 | $recaptcha_response->error = 'incorrect-captcha-sol'; 169 | return $recaptcha_response; 170 | } 171 | 172 | $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", 173 | array ( 174 | 'privatekey' => $privkey, 175 | 'remoteip' => $remoteip, 176 | 'challenge' => $challenge, 177 | 'response' => $response 178 | ) + $extra_params 179 | ); 180 | 181 | $answers = explode ("\n", $response [1]); 182 | $recaptcha_response = new ReCaptchaResponse(); 183 | 184 | if (trim ($answers [0]) == 'true') { 185 | $recaptcha_response->is_valid = true; 186 | } 187 | else { 188 | $recaptcha_response->is_valid = false; 189 | $recaptcha_response->error = $answers [1]; 190 | } 191 | return $recaptcha_response; 192 | 193 | } 194 | 195 | /** 196 | * gets a URL where the user can sign up for reCAPTCHA. If your application 197 | * has a configuration page where you enter a key, you should provide a link 198 | * using this function. 199 | * @param string $domain The domain where the page is hosted 200 | * @param string $appname The name of your application 201 | */ 202 | function recaptcha_get_signup_url ($domain = null, $appname = null) { 203 | return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); 204 | } 205 | 206 | function _recaptcha_aes_pad($val) { 207 | $block_size = 16; 208 | $numpad = $block_size - (strlen ($val) % $block_size); 209 | return str_pad($val, strlen ($val) + $numpad, chr($numpad)); 210 | } 211 | 212 | /* Mailhide related code */ 213 | 214 | function _recaptcha_aes_encrypt($val,$ky) { 215 | if (! function_exists ("mcrypt_encrypt")) { 216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); 217 | } 218 | $mode=MCRYPT_MODE_CBC; 219 | $enc=MCRYPT_RIJNDAEL_128; 220 | $val=_recaptcha_aes_pad($val); 221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); 222 | } 223 | 224 | 225 | function _recaptcha_mailhide_urlbase64 ($x) { 226 | return strtr(base64_encode ($x), '+/', '-_'); 227 | } 228 | 229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ 230 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { 231 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { 232 | die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . 233 | "you can do so at http://www.google.com/recaptcha/mailhide/apikey"); 234 | } 235 | 236 | 237 | $ky = pack('H*', $privkey); 238 | $cryptmail = _recaptcha_aes_encrypt ($email, $ky); 239 | 240 | return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); 241 | } 242 | 243 | /** 244 | * gets the parts of the email to expose to the user. 245 | * eg, given johndoe@example,com return ["john", "example.com"]. 246 | * the email is then displayed as john...@example.com 247 | */ 248 | function _recaptcha_mailhide_email_parts ($email) { 249 | $arr = preg_split("/@/", $email ); 250 | 251 | if (strlen ($arr[0]) <= 4) { 252 | $arr[0] = substr ($arr[0], 0, 1); 253 | } else if (strlen ($arr[0]) <= 6) { 254 | $arr[0] = substr ($arr[0], 0, 3); 255 | } else { 256 | $arr[0] = substr ($arr[0], 0, 4); 257 | } 258 | return $arr; 259 | } 260 | 261 | /** 262 | * Gets html to display an email address given a public an private key. 263 | * to get a key, go to: 264 | * 265 | * http://www.google.com/recaptcha/mailhide/apikey 266 | */ 267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { 268 | $emailparts = _recaptcha_mailhide_email_parts ($email); 269 | $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); 270 | 271 | return htmlentities($emailparts[0]) . "...@" . htmlentities ($emailparts [1]); 273 | 274 | } 275 | 276 | 277 | ?> 278 | -------------------------------------------------------------------------------- /simple_chat/register.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_chat/register_form.php: -------------------------------------------------------------------------------- 1 | 28 | 29 | 30 | 31 | Registration Form 32 | 33 | 34 | 68 | 69 | 70 |
71 |
72 |
73 |

Registration Form

74 |
75 | 76 |
77 |
78 | 79 | -------------------------------------------------------------------------------- /sql/simple_chat.sql: -------------------------------------------------------------------------------- 1 | SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 2 | SET time_zone = "+00:00"; 3 | 4 | 5 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 6 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 7 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 8 | /*!40101 SET NAMES utf8 */; 9 | 10 | CREATE TABLE IF NOT EXISTS `message` ( 11 | `mid` int(10) unsigned NOT NULL AUTO_INCREMENT, 12 | `content` varchar(255) DEFAULT NULL, 13 | `uid` int(10) unsigned NOT NULL, 14 | `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 15 | PRIMARY KEY (`mid`), 16 | KEY `uid` (`uid`) 17 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 18 | 19 | 20 | CREATE TABLE IF NOT EXISTS `user` ( 21 | `uid` int(10) unsigned NOT NULL AUTO_INCREMENT, 22 | `uname` varchar(25) NOT NULL, 23 | `passwd` varchar(64) NOT NULL, 24 | PRIMARY KEY (`uid`), 25 | UNIQUE KEY `uname` (`uname`), 26 | KEY `passwd` (`passwd`) 27 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 28 | 29 | 30 | ALTER TABLE `message` 31 | ADD CONSTRAINT `message_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`); 32 | 33 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 34 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 35 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 36 | --------------------------------------------------------------------------------