Jump to content

RandomChatroom


TehBlizzy

Recommended Posts

EDIT: I removed the links.Put these in a folder with write permission. Remove the .txt extensions. Load chat.html into a bunch of different browsers and have a party. Let me know if something breaks.As before, you'll need to adapt it to your own purposes.And let me know when you've downloaded them so I can remove the links.

Link to comment
Share on other sites

I've uploaded it and modified what I needed, but the username box will be hidden and it's value will be the session name and I got that to appear, but the alert error "Sorry: 302" keeps appearing. Wth? >>

Link to comment
Share on other sites

I see it's up, that's great. You'll want a faster server in the future, but it'll keep.Before you open it up to the public, you'll want to take other security meaures into mind. The big one is upload size. Someone could easily download the html page, change it around, and upload 100K every time they hit enter. In a minute, you'd hit your file quota. So you'll want to reject anything over a certain size.

Link to comment
Share on other sites

I completely jumped ahead by modifying my whole chatroom code twice, and I got lost... so I deleted everything.This is basically my new chatroom code and it comes up with no error, but the page refreshes. Why? >>

<?phpsession_start();?><html><head><title>Random Chatroom - Room One </title><link href='http://randomchatroom.zxq.net/css/red.css' rel='stylesheet' type='text/css'></head><script type="text/javascript">		 var hObj; //must be global		 function hPostData() {			var myData = document.getElementById("message").value;			hObj = null;			var myURL = "scripts/post_message.php";			if (hObj = getHObject()){			   hObj.onreadystatechange = hStateChanged;			   hObj.open ('POST', myURL, true);			   hObj.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");			   hObj.send (myData);			}else {alert ("Cannot get an HTTP object");}		 }		 function hStateChanged() {			if (hObj.readyState == 4) {			  if (hObj.status == 200) {				 printResponse(hObj.responseText);			  }else{				 alert ('Sorry: ' + hObj.status);			  }		   }		 }		 function getHObject() {			var hObj = null;			try {hObj = new XMLHttpRequest();}			catch (e) {			   try {hObj = new ActiveXObject('Msxml2.XMLHTTP');}			   catch (e) {hObj = new ActiveXObject('Microsoft.XMLHTTP');}			}			return hObj;		 }		 function printResponse(myText) {			var messages = document.getElementById('messages');			messages.innerHTML = myText;		 }</script><body><center><table border="1" width="800" height="600"><tr><td colspan="2" height="100"><center><h1>Random Chatroom - Room One</h1></td></tr><tr><td height="400" width="600"><div id="messages">messages go here</div></td><td><div id="current_users">user list goes here</div></td></tr><tr><td><div align="center"><form method="POST"><input type="text" value="<?php echo($_SESSION[myusername]); ?>" id="username"><input type="text" size="32" id="message">   <input type="submit" onClick="hPostData()" value="Send!"></td></tr></table></body></html>

This is my post_message.php:

<?phpsession_start();$username = $_SESSION['myusername'];$message = $_POST['message'];$fp = fopen('messages/room_one.txt, 'a');fwrite($fp, '$username : $message');fclose($fp)?>

I kinda deleted everything without saving the important code(s).. :S

Link to comment
Share on other sites

You need an onsubmit handler in your form tag, not your submit button, and it should return false after it calls its function. Thus: onsubmit="doSomething(); return false"; The reason you're refreshing is that you don't have an action specified in your form tag, and refreshing the page is the default action. Not widely known, but true. :)

Link to comment
Share on other sites

  • 2 weeks later...

I've started messing with it again.. changed a bit of it... and its not doing anything...? I even added alert("TESTING!"); to very first line of the sendMessage() function and it didn't do anything??? What did I do wrong?

<?phpsession_start();?><html><head><title>Random Chatroom - Room One </title><link href='http://randomchatroom.zxq.net/css/red.css' rel='stylesheet' type='text/css'></head><script type="text/javascript">function sendMessage() {var xmlHttp;try  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }catch (e)  {  // Internet Explorer  try	{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	}  catch (e)	{	try	  {	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	  }	catch (e)	  {	  alert("Your browser does not support AJAX!");	  return false;	  }	}  }  var message = document.getElementById("message").value;  xmlHttp.open('POST', scripts/post_message.php, true); xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");  xmlHttp.setRequestHeader("Content-length", parameters.length);  xmlHttp.setRequestHeader("Connection", "close");  xmlHttp.send(message);}</script><body><center><table border="1" width="800" height="600"><tr><td colspan="2" height="100"><center><h1>Random Chatroom - Room One</h1></td></tr><tr><td height="400" width="600"><div id="messages">messages go here</div></td><td><div id="current_users">user list goes here</div></td></tr><tr><td><div align="center"><form method="POST" onSubmit="postMessage();return false;" action=""><input type="text" value="<?php echo($_SESSION[myusername]); ?>" id="username"><input type="text" size="32" id="message">   <input type="submit" value="Send!"></td></tr></table></body></html>

Link to comment
Share on other sites

Once I get the sessions to work, I'll check that out. I added an if to check if the session is being set, and it is, but it comes up with an error:

Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php5) in Unknown on line 0

I guess that means the server or w/e can't save the session or something?

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...