|
-
the cheesy child
Flash PHP SQL chatroom
Hello, I am trying to make a chatroom.
what I have been doing is using php to send the message to a txt file. flash reads this txt file and puts it onto the chat.
but i dunno why but the chat message keeps sending and sending...
SOOOO
It Turns out that its best to have a place you can store heaps of information without stuff getting too slow... I think SQL might be the job.
SO THIS IS WHAT I NEED
I need a tutorial or somebody to show me on how to make a flash, PHP, SQL chatroom that teaches you to connect with PHP and all that stuff.
anyways hopefully i can get a chatroom working soon.
-
FK'n_dog
search GOOGLE - flash, PHP, SQL chatroom tutorial
-
Bearded (M|G)od
This is probably the worst way to make a chat room. Just throwing that out there.
-
FK'n_dog
http://www.jackleaman.co.uk/test/wri..._autoLoad.html
i have sent you this link before. saved to .txt file. show last 20 entries only.
can you not make use of the methods in the zipped file ??
-
the cheesy child
Ok just last night I made a chatroom with php and txt myself without the file a_modified.
You see problem is, It has errors and stuff and I was hoping SQL was somewhere to store data into such as a chat message.
but nevermind. I will just stick with the glitchy chatroom i made...
and i guess SQL can't support a multiplayer online game either...?
-
Bearded (M|G)od
bounceboy, you're using the most awkward technologies for what you want to do.
Writing out to a text file with every message, and polling that text file every x seconds is extremely inefficient and accident prone.
Even polling a database for that is messy.
What you're digging into, you should look into a real time media server. Something like Red5 or FMS. Those are meant for these types of things. Chat rooms and multiplayer games.
-
Hi,
may I oppose: real time servers do not run on your regular web space, so one needs to run them on the home computer or pay a hosting bill. For a general web site, with a chat just as one element, building the chat with traditional web technology certainly is an option.
I have used a sql-based chat built on this schema:
the database maintains an id column as well as a date column, and polls to the server (reasonable intervals seem to be in the 3-10 seconds range) send the last message id received. So if nothing happens, the poll response ist just the same id again - only new messages are actually sent over the network
a new person in the chat can potentially request the last # messages or last # minutes before login
Musicman
-
the cheesy child
Musicman that sounds like what i am after. is there a tutorial or something?
-
Hi,
unfortunately there is not.... so these are just code snippets
database structure:
Code:
create table chat (
id int not null auto_increment primary key,
user varchar(20),
posted int, -- actually a timestamp
message text
);
Note: this assumes magic_quotes on, otherwise add addslashes()
Code:
<?
include "db.php"
if(isset($_POST['user']) && isset($_POST['message']))
{ $user = $_POST['user'];
$message = $_POST['message'];
mysql_query("insert into chat (user, posted, message) values ('$user', unix_timestamp(), '$message')");
}
else if(isset($_POST['id']))
{ $lastid = $_POST['id'];
if(!ereg('^[1-9][0-9]*', $lastid)) exit;
$ret = mysql_query("select * from chat where id > $lastid order by id");
$chat = '';
while($row = mysql_fetch_array($row))
{ $chat .= "posted by <font color='#00ff00'>{$row['user']}</font> on " . date("h:m", $row['posted']) . "<br>" . htmlspecialchars($row['message']) . "<br>---------<br>";
$lastid = $row['id'];
}
if($chat != '') print "&chat=$chat";
print "&id=$lastid&";
}
Now, on the flash side, an interval timer would repeatedly send the id to the server and get the id back. If there is a chat variable in the response, add to display (and possibly scroll to the end so it becomes visible)
Code:
var lastid = 0;
function poll()
{ var sendlv = new LoadVars();
var retlv = new LoadVars();
sendlv.id = lastid;
retlv.onLoad = function() {
lastid = this.id;
if(this.chat != undefined) {
chattext.htmlText += this.chat;
chattext.scroll = chattext.maxscroll;
}
};
}
Musicman
-
the cheesy child
Thank you very much! I will try this out as soon as I can.
Also I've made a chatroom with PHP and TXT. the flash script is not very different...
-
the cheesy child
wait wait.... are the first two codes for PHP?
where does the first go?
I'm not some expert at PHP sorry
-
Hi,
the first one is definition of a database table, and the second one is a minimal php script that uses this database
Musicman
-
the cheesy child
dorry ummm im new to databases and this probably isn't the best way to start...
i have made a database with my server, where do i go to create the table in the database... on my server i cant really edit it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|