Copy link to clipboard
Copied
Below is what i understand how a live chat application can be created.
Please make any changes and revert.
Work Flow
1. Visitor logs in to chat, providing name and email id
2. create sessions for loggedin users
3. Welcome note send to visitor.
4. Visitor initiates chat ('hi','hello')
5. admin reply to chat.
Backend process
1. admin can view all logged in users
2. text sent by visitor via visitor chat panel will be visible at admin chat panel.
3. Admin reply ('hi') should be sent to that particular user only.
Database (please updated DB i made it as per my understanding)
Visitor table
v_id
v_name
v_text
v_texttime (at what time the text was sent)
v_conversation (updated complete conversation )
v_status
admin table
a_id
a_name
will i require IP address of visitor, if yes then please let me know what data type i must use for it. As well as how i can use the visitor IP address in this application.
I will require to program in ajax (correct me if i am wrong )as only that program (live chat) will need to access the php script each time text is sent.
Please let me know the basic syntax of ajax, i need to create a very simple chat application.
Thank you in advance.
Copy link to clipboard
Copied
The table design would work for simple application, but I would probably do it differently. In fact, I wouldn't do it at all, since there are already dozens of free and inexpensive chat scripts already available.
>Please let me know the basic syntax of ajax,
Not sure what you're asking. If you're not familiar with ajax then check out one of the thousands of examples on the web and then follow some of the tutorials.
Copy link to clipboard
Copied
Thank you Mr.Bregent,
thank you for the advice, Unable to find free open source chat application.
If possible please suggest a open source preferably php chat application. So that i may use my time in some different application.
Below i have shared the code i wrote for Live chat (stupid code though)
Used ajax to run send.php file.
jquery to append the text
Can anyone suggest the logic behind chat application.
Each logged in user will have a chat window and when the admin(one who will reply back to chat) text should be sent only to that user.
<?php
if (!isset($_SESSION)) {
session_start();
}
$login = $_SERVER['PHP_SELF'];
if (isset ($_POST["loginform"]) && ($_POST["loginform"]=="formlogin")){
$_SESSION['name']=$_POST['txtname'];
$_SESSION['emailid']=$_POST['txtemailid'];
}
$send = $_SERVER['PHP_SELF'];
if (isset ($_POST["send"]) && ($_POST["send"]=="sendform")){
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Live chat</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function send()
{
var sendtxt =document.getElementById("txtinput").value;
debugger;
if (sendtxt.length == 0) {
document.getElementById("txt").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
$(document).ready(function(){
$("#txt").append("<br>" +xmlhttp.responseText + "</br>");
alert(xmlhttp.responseText) ;
});
;
}
}
xmlhttp.open("GET", "send.php?q=" + sendtxt, true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form id="login" name="login" method="post" action="<?php echo $login; ?>">
name<input type="text" id="txtname" name="txtname" > <br>
email <input type="text" id="txtemailid" name="txtemailid" ><br>
<input type="submit" value="Login" >
<input type="hidden" name="loginform" value="formlogin">
</form>
<div id="chat" style="width:500px; height:250px; overflow:scroll; border:thin solid;" >
<div id="txt" style="width:500px; height:200px;">
</div>
<div id="chattext" style="position:fixed">
<input type="text" id="txtinput" width="500px" height="50px">
<input type="submit" value="Send" onclick="send()">
</div>
</div>
</body>
</html>
send.php file code
<?php
// get the q parameter from URL
if (!isset($_SESSION)) {
session_start();
}
$q = $_REQUEST["q"];
echo $q;
?>
Copy link to clipboard
Copied
>thank you for the advice, Unable to find free open source chat application.
Really? How are you searching? I can't make any recommendations because I haven't personally used them, but here's a quick list. Probably many more out there if you search.
PHP Chat Scripts - Free, commercial and open source chat scripts