Jump to content

Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (14 April 2014 - 05:28 PM) By The Way, This Could Be An Interesting Subject For A Topic, What About Posting This Question? Let's See If Other People Have The Same Feeling Concerning Bootlists!
@  yordan : (13 April 2014 - 09:36 AM) Boot Order : Cd, [Usb,] Hard Drive :D
@  yordan : (11 April 2014 - 07:23 PM) I Simply Let The Bios Do That
@  Ritesh : (11 April 2014 - 10:23 AM) Is It Possible To Launch Fedora Live Cd Or Installation Disk From Hard Drive On Windows Platform Using Grub Mbr File.
@  Ritesh : (11 April 2014 - 10:21 AM) No U Are Not.. Btw.. I Have Question For You.
@  yordan : (10 April 2014 - 08:02 AM) You Are Partially Right.
I Was Not.
Nevertheless, I Am Again :)
@  Ritesh : (09 April 2014 - 07:33 PM) :P
@  Ritesh : (09 April 2014 - 07:33 PM) I Think U R Not..
@  yordan : (09 April 2014 - 09:28 AM) I'm The Master Of The Shoutbox!
@  yordan : (05 April 2014 - 10:32 PM) He-He
@  Ritesh : (04 April 2014 - 06:59 PM) Ha Ha Ha ....
@  yordan : (04 April 2014 - 11:15 AM) Welcome Back, Starscream!
@  yordan : (03 April 2014 - 02:31 PM) And I Hope That He Will Come Back Soon :)
@  yordan : (01 April 2014 - 02:53 PM) Nice, Ritesh Came, I'm Not Home Alone Today.
@  Ritesh : (01 April 2014 - 08:51 AM) Oh!!! Poor Dear Yordan..
@  yordan : (31 March 2014 - 10:02 AM) I'm A Poor Lonesome Cow-Boy
@  yordan : (27 March 2014 - 02:22 PM) He Is Unpatient Due To His Patients!
@  Ritesh : (27 March 2014 - 10:46 AM) :(
@  Ritesh : (27 March 2014 - 10:46 AM) He Is Busy With His Patients.
@  yordan : (26 March 2014 - 08:12 PM) Ahsani, Where Are You?

- - - - -

More Advanced Shoutbox A more advanced shoutbox with fewer files and no refresh needed

3 replies to this topic

#1 8ennett


    Premium Member

  • Members
  • 415 posts
  • Gender:Male
  • Location:UK
  • myCENTs:95.20

Posted 03 February 2010 - 03:50 PM

First of all you will need to create the following documents and copy and paste the contents of the below code in to them:

<?php    session_start();  mysql_connect ('MYSQL HOST', 'MYSQL USERNAME', 'MYSQL PASSWORD');    mysql_select_db ('DATABASE NAME');  if (isset($_GET['sendshout']) && !isset($_GET['readshout'])){    $shout = mysql_real_escape_string(trim(htmlentities(strip_tags($_POST['message']))));    mysql_query("INSERT INTO shoutbox (user, date, content, name) VALUES ('".$_SESSION['id']."', '".time()."', '".$shout."', '".$_SESSION['username']."')");    }    if (isset($_GET['readshout']) && !isset($_GET['sendshout'])){    $query = mysql_query("SELECT * FROM shoutbox ORDER BY date DESC LIMIT 0, 10");    while($row = mysql_fetch_assoc($query)){    echo "<strong>".$row['name'].":</strong> ".stripslashes($row['content']);."<br />";    }    }  mysql_close ('MYSQL HOST', 'MYSQL USERNAME', 'MYSQL PASSWORD');    ?>

function ajaxFunction(){  var ajaxRequest;   try{    // Opera 8.0+, Firefox, Safari    ajaxRequest = new XMLHttpRequest();    } catch (e){    // Internet Explorer Browsers    try{    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");    } catch (e) {    try{    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    } catch (e){    //browsers all not support, rare case    alert("Your browser does not support ajax, please use Mozilla Firefox!");    return false;    }    }   }    return ajaxRequest;    }  function showData() {    htmlRequest = ajaxFunction();    if (htmlRequest==null){    alert ("Browser does not support HTTP Request");    return;    }    htmlRequest.onreadystatechange = function(){    if(htmlRequest.readyState == 4){    document.getElementById("shoutarea").innerHTML = htmlRequest.responseText;    }    }    htmlRequest.open("GET", "shoutbox.php?readshout=true", true);    htmlRequest.send(null);    }  showData();    setInterval("showData()",1000);  function saveData(){    htmlRequest = ajaxFunction();    if (htmlRequest==null){    alert ("Browser does not support HTTP Request");    return;    }    if(document.shoutbox.message.value == "" || document.shoutbox.message.value == "NULL"){    alert('You need to type a message!');    return;    }    htmlRequest.open('POST', 'shoutbox.php?l=sendshout=true', true);    htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    htmlRequest.send('message='+document.shoutbox.message.value);    document.shoutbox.message.value = '';  document.shoutbox.message.focus();  }

<html>    <head>    <script language="JavaScript" type="text/javascript" src="shoutbox.js"></script>    <title>Shoutbox</title>    </head>    <body>    <form id="shoutbox" name="shoutbox" method="POST" onSubmit="saveData(); return false;">    <div id="shoutarea"></div><br /><input $id="message" name="message" type="text" size="50" maxlength="100" class="textbox" /><input type="submit" name="submit" value="submit"/>    </form>    </body>  </html>

You will also need to run the following MySQL query either in the console or using phpMyAdmin:

CREATE TABLE `shoutbox` (
`id` integer(255) NOT NULL auto_increment,
`user` integer(255) NOT NULL,
`date` integer(255) NOT NULL,
`content` varchar(100) NOT NULL,
`name` varchar(45) NOT NULL,

Now the above files assume that you have already written to your session the following variables,
$_SESSION['id'] : This is the current users unique id number
£_SESSION['username'] : The current users display name

These variables would usually be set in some kind of user login script however to test the shoutbox you could just write them in to the shoutbox.php script.

Now what happens above, the ajax javascript file contains all the custom functions required to operate the shoutbox. We include this in the head of the our html (or php) index file soit can be used when submitting our form. The forms onSubmit function being used to call the saveData function from the javascript document. I think the rest is actually pretty self-explanatory so have fun testing it out.

Just to recap quickly, in shoutbox.php where there is the following line:
mysql_connect ('MYSQL HOST', 'MYSQL USERNAME', 'MYSQL PASSWORD');  mysql_select_db ('DATABASE NAME');
Replace MYSQL HOST with your hostname eg. localhost, MYSQLUSERNAME with your username eg. root, and MYSQL...well you get the idea. Also do the same for the very last line of code in shoutbox.php. Also replace the two $_SESSION variables outlined above with what ever your site uses.

#2 8ennett


    Premium Member

  • Members
  • 415 posts
  • Gender:Male
  • Location:UK
  • myCENTs:95.20

Posted 18 March 2010 - 08:43 PM

I've just noticed a problem in the shoutbox.js code, where it says 'shoutbox.php?l=sendshout=true' remove the l= so it looks like 'shoutbox.php?sendshout=true' My mistake!

#3 starscream


    Super Member

  • Members
  • 896 posts
  • Gender:Male
  • Location:Land of Shadows
  • myCENTs:84.35

Posted 19 March 2010 - 08:32 AM

if you can fix the shourbox issue in trap17.com then let opaque know about it. it is broken and needs some attention. if you can help with that for trap17 then that will be good. you can sign up at trap17 and earn mycents there as well. so see how shoutbox is broken and check if you can fix that. we seriously need fix for that.

#4 8ennett


    Premium Member

  • Members
  • 415 posts
  • Gender:Male
  • Location:UK
  • myCENTs:95.20

Posted 19 March 2010 - 06:49 PM

I'm a bit too busy to be signing up for any more forums at the moment, my site needs to be up and running within 6 months and it's a lot of work for just one person. In fact I've just finished perfecting this shoutbox, included smileys, different chat rooms with one script, alerts when people enter or leave the chat and even whispering to others inside the chat window.

Anyway, without being able to see the full structure of the shoutbox (eg. PHP) I doubt I could offer any advice on fixing it anyway. I'm sure opaque will get around to fixing it if he has the time. It's probably a problem with the query.

Reply to this topic


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users