Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <title>Chatbox 1.0</title>
- <link type="text/css" rel="stylesheet" href="CSS/cb.css">
- <div class="head">
- <div class="main">
- </div>
- <div class="des">
- This is beta version 1.0 of the Chatbox!
- </div>
- </div>
- <?php
- session_start();
- if($_SESSION['username'] == "")
- {
- echo "<script type='text/javascript'>alert('Please sign in to use our service.');</script>";
- echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/';",100);
- </script>";
- exit();
- }
- $subject = $_SESSION['chat'];
- if($subject == ""){
- $subject ="helloworld";
- }
- elseif(file_exists($subject)){
- $myfile = fopen($subject,"r");
- if(strpos("," . base64_decode($_SESSION['username']))===FALSE){
- echo "<script type='text/javascript'>alert('You do not have permission to access this chat.');
- </script>";
- echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/';",100);</script>";
- }
- }
- echo "signed in as " . base64_decode($_SESSION['username']);
- $usernam = "chatboxd_cbox";
- $servername = "198.91.81.8";
- $password = "cbox";
- $conn = new mysqli($servername, $usernam, $password);
- // Check connection
- if
- ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- echo "
- <br>Connected successfully to " . $_SESSION['chat'] ;
- $msg = "";
- if(isset($_POST['submit']))
- {
- sendmsg();
- getmsg();
- }
- if(isset($_POST['refresh']))
- {
- getmsg();
- }
- if(isset($_POST['switch']))
- {
- $GLOBALS['subject'] = base64_encode(test_input($_POST["targetchat"]));
- $_SESSION['chat'] =test_input($_POST["targetchat"]);
- getmsg();
- }
- if(isset($_POST['logout']))
- {
- session_destroy();
- echo "<script type='text/javascript'>alert('You have logged out.');
- </script>";
- echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/index.php';",100);
- </script>";
- exit();
- }
- function sendmsg(){
- // define variables and set to empty values
- if ($_SERVER["REQUEST_METHOD"] == "POST")
- {
- $msg = base64_encode(test_input($_POST["msg"]));
- $username = $_SESSION['username'];
- $usernam = "chatboxd_cbox";
- $servername = "198.91.81.8";
- $password = "cbox";
- $db = "chatboxd_chats";
- $conn = new mysqli($servername, $usernam, $password,$db);
- $datetim = base64_encode(date("r"));
- $sql = "INSERT INTO " . $GLOBALS['subject'] ."
- VALUES ('$username','$datetim','$msg')";
- if ($conn->query($sql) === TRUE) {
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- }
- function getmsg(){
- $usernam = "chatboxd_cbox";
- $servername = "198.91.81.8";
- $password = "cbox";
- $db = "chatboxd_chats";
- $conn = new mysqli($servername, $usernam, $password,$db);
- $sql = "SELECT * FROM " .$GLOBALS['subject'];
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc())
- {
- echo "<br>" . base64_decode($row["user"]). " said: " . base64_decode($row["message"]). " on " . base64_decode($row["datetime"])."<br>";
- }
- }
- else {
- echo "<br>No messages were found to display! Start sending them now!";
- }
- if ($conn->query($sql)===FALSE){
- echo("Error: " . $sql . "<br>" . $conn->error);
- }
- }
- function test_input($data)
- {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <div class="chatbox">
- <p name = "subject">
- hello world.txt
- </p>
- <div class="chatlogs" id="sc" onload="sc();">
- <?php
- ?>
- </div>
- </div>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Message:<textarea name ="msg"></textarea>
- <input type ="submit" name = "submit" value ="Send">
- <input type="submit" name="logout" class="logout" value="Logout" />
- <input type="submit" name="switch" class="switch" value="Change to another chat:" />
- <input name = "targetchat"/>
- </form>
- </body>
- <script>
- var objDiv = document.getElementById("sc");
- objDiv.scrollTop = objDiv.scrollHeight;
- function sc(){
- setTimeout(scroll(), 100);
- }
- function scroll(){
- var objDiv = document.getElementById("sc");
- objDiv.scrollTop = objDiv.scrollHeight;
- }
- setTimeout(function(){
- window.location.reload(1);
- }, 60000);
- </script>
- </html>
Add Comment
Please, Sign In to add comment