I'm beginner to php/mysql (quite familiar with PHP, mysql), novice to XMPP.

I have created my site in simple php/mysql/javascript/jquery. I'm trying to add simple Private Chat to my web site.

Trying to integrate JSXC Chat into my website.

Please Guide me how to create chat database, install XMPP server, and add jsxc to my site.
I'm using XAMPP Server v3.2.2 on 64 bit Windows 10

Need help to finish this stuff.

Links

PHP Login Script,
JSXC chat

Thanks in advance

Member Avatar for diafol

WHy don't you show what you've done and be specific with where you're fidning difficulty. One thing at a time - one thread - one question (e.g. install XMPP). Throwing in the kitchen sink in the OP tends to scare off contributors as the task of answering the question is beyond the amount of time available. I generally give 2-5 minutes thought to an OP - more if it interests me.

I take a minute to read content at one of your links. https://www.jsxc.org/contact.html shows a mailing list where I hope you've joined and checked out priors and maybe asked them more questions.

The install is not trivial and I see no mention of what I read in their install pages. That is, time to go over the install notes again.

I have installed ejabberd Community Server on windows. Need help to configure using following paths of servers.

Get login code from github, - Simple-PHP-Login.
After logged in there is Members Area i.e. members.php

How to integrate jsxc chat using this login code in Members Area?
Need to maintain chat message database

There is same origin policy (SOP). How to configure server to make it work? Should I start New thread for server configuration ???

I have account with bluehost. So all code will be transfered from windows PC to Linux server.

Path for Xmpp server and XAMPP Server
  1. Xmpp server :- D:\ejabberd-16.12.beta1
  2. xampp server :- D:\Server\htdocs\XmppChat

Thanks

( I'm newbie :(
so, be kind, please )

Database: xmppchat

CREATE TABLE `users` (
  `userid` bigint(12) NOT NULL,
  `username` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL,
  `password` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

config.php

<?php

$host = "localhost";
$user = "srnj";
$pass = "123456"; 
$database = "xmppchat";

$link = mysql_connect($host, $user, $pass);
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
    die ('Can\'t use database: ' . mysql_error());
}
?>

index.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<a href="login.php">login</a>

<a href="dashboard.php">dashboard</a>
</body>
</html>

login.php

<?php
//xmppchat
include("include/config.php");

if(!isset($_COOKIE['token'])) { 

?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  <table border="0">
    <tr>
      <td colspan=2><h1>Login</h1></td>
    </tr>
    <tr>
      <td>Username:</td>
      <td><input type="text" name="username" id="username" maxlength="40"></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="pass" id="password"  maxlength="50"></td>
    </tr>
    <tr>
      <td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td>
    </tr>
  </table>
</form>
</body>
</html>
<?php  

} 

 if (isset($_POST['submit'])) {

     if(!$_POST['username']){
        die('You did not fill in a username.');
    }
    if(!$_POST['pass']){
        die('You did not fill in a password.');
    }

    $check = mysql_query( "SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
    $check2 = mysql_num_rows($check);
     if ($check2 == 0){

        die('That user does not exist in our database.<br />');     
    }

    while ($row = mysql_fetch_assoc($check)) {

        $_POST['pass'] = stripslashes($_POST['pass']);
        $row['password'] = stripslashes($row['password']);
        $_POST['pass'] = md5($_POST['pass']);

        $userid= $row["userid"];

        //gives error if the password is wrong
        if ($_POST['pass'] != $row['password']){
            die('Incorrect password, please try again.');
        }else{ // if login is ok then we add a cookie 

            $hour = time() + 3600; 
            //setcookie('username', $_POST['username'], $hour); 
            setcookie('token', $userid, $hour);  

            //then redirect them to the members area 

            echo '<script type="text/javascript">window.location="dashboard.php";</script>';
        }
    }//while

}

 ?>

dashboard.php

<?php

$cookie_name = "token";

if(!isset($_COOKIE[$cookie_name])) {
    echo "You are not logged in!";
    echo"<br />";
    echo ' <script type="text/javascript">         
            function Redirect() {
               window.location="login.php";
            }            
            document.write("You will be redirected to main page in 5 sec.");
            setTimeout("Redirect()", 5000);         
      </script>';
} else {

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<table border="1" >
  <tr >
    <td>
        <?php
            echo "Cookie '" . $cookie_name . "' is set!<br>";
            echo "Value is: " . $_COOKIE[$cookie_name];
            echo "<br>";
            echo "Admin Area<p>"; 
            echo "Your Content<p>"; 
            echo "<a href=logout.php>Logout</a>"; 
        ?>
    </td>
  </tr>
</table>
</body>
</html>
<?php
}
?>

logout.php

<?php 
$past = time() - 100; 
//this makes the time in the past to destroy the cookie 
setcookie('token', 'gone', $past); 
header("Location: login.php"); 
?>

Please Somebody Help Me....

I don't mean to troll or spam, but why not just use Dazah to create a chat? It handles all the database stuff.

Member Avatar for diafol

Troll

commented: :-P +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.