|
|
|
|
![]() ![]() |
Apr 7 2008, 09:38 AM
Post
#1
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 45 Joined: 8-December 07 Member No.: 54,414 |
With this tutorial, you will learn how to create a simple shoutbox, but only uses a .txt file. Also with auto refresh, and I am going to do a backgound.
We will be making 5 files. 1. index.php The main page 2. msg.php Reading msg.txt 3. msg.txt Note: You must give it 777 4. shout.php Where it add to msg.txt 5. bg.gif Background. Index.php would be like this: CODE <html> <head> <title>Shoutbox</title> </head> <body> <iframe src="msg.php" marginwidth="1" marginheight="0" height="200"width="153" border="0" frameborder="0"></iframe> <FORM name="shout" action="shout.php" method="POST"> Name:<br> <INPUT TYPE="TEXT" name="name" size="20"><br> Message:<br> <INPUT TYPE="TEXT" name="message" size="20"><br> <br> <INPUT TYPE="Submit" name="submit" value="Shout!" size="20"> </FORM> </body> </html> Let's go over what the code do. <html> -> <body> are just the title. <iframe> gets msg.php which gets msg.txt. You will know why I do that later. <FORM> -> </FORM> is where you can type what you want to shout. Now let's make the msg.php! CODE <html> <head> <meta http-equiv="refresh" content="8;url=msg.php" /> </head> <body> <?php include('msg.txt'); ?> </body> </html> I shouldn't really explan this. Meta refresh the page every 8 sec. <?php include gets msg.txt. I did this was for it won't refresh the whole page, as if it refresh while typing it will rub out the msg. Just make a msg.txt with 777. And for shout.php: CODE <?php $name = $_POST['name']; $message = $_POST['message']; $code = array( '/:\)/', '/:P/', '/:D/' //Bla bla bla ); $image = array( '<img src="smileys/1.gif">', '<img src="smileys/2.gif">', '<img src="smileys/3.gif">' // Bla bla bla ); $formatted = preg_replace($code, $image, $message); $tag = ("<font size=\"2\" face=\"Arial\"><b> $name:</b>$message </font><br>"); $read = fopen("content.txt", "r"); $contents = fread($read, filesize('content.txt')); fclose($read); $write = fopen("content.txt", "w"); fwrite($write, "$tag $contents"); fclose($write); print "<meta http-equiv=\"refresh\" content=\"0;index.php\">"; ?> I made a little smiley feature, and you can use it for bb codes like [heading] turns to <h2> and stuff. Hope you enjoyed the tut! |
|
|
|
Jun 8 2008, 08:14 PM
Post
#2
|
|
|
Newbie ![]() Group: Members Posts: 7 Joined: 8-June 08 Member No.: 63,355 |
OMFG, this was so helful, Even without any PHP-programming skills, I managed to add some new smilieys and get it to work according to my wishes
only problem I had was that there was no space between two posts. however, I managed to fix this, but it was not in any of these files frome this tutorial, i got to change css-files, create new css-files and edit some other HTML-code. Once again, GREAT tutorial! you made my understanding for PHP bigger now too.... but there is ONE thing. how do I make a check so that the user did type in a message, so i don't get empty messages (SPAM)?? This post has been edited by datanizze: Jun 8 2008, 08:28 PM |
|
|
|
Jun 17 2008, 03:59 AM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: [HOSTED] Posts: 12 Joined: 17-June 08 From: Aurora, Colorado Member No.: 63,742 |
My browser tries to save the .php file every time I press shout
|
|
|
|
Jun 21 2008, 07:38 AM
Post
#4
|
|
|
Newbie [Level 2] ![]() ![]() Group: [HOSTED] Posts: 35 Joined: 19-September 06 From: Higara Member No.: 30,215 |
My browser tries to save the .php file every time I press shout You are probably running it from your computer without php installed. You can download software like Easy PHP, WAMP. Just search them on google. Then copy those files to something like www or htdocs in the installation folder and run the server. |
|
|
|
Jun 25 2008, 09:44 PM
Post
#5
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 151 Joined: 19-June 08 From: United Kingdom - Cornwall!!!!! Member No.: 63,876 |
Nice tutorial, havent used it yet, but i must! as i havent done any PHP for a long time, and intend to do some more before i start creating my new website!
Nice thread! |
|
|
|
Jun 25 2008, 10:43 PM
Post
#6
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 603 Joined: 13-December 06 Member No.: 35,271 |
Nice and simple, I love it. You really put a lot of care into this tutorial. Well done mate. I may be using this myself sometime.
Perhaps you could post some suggested different CSS styles for this. |
|
|
|
Jul 21 2008, 09:46 AM
Post
#7
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 45 Joined: 8-December 07 Member No.: 54,414 |
Thanks guys. Some guy has stole my tut, so I need to get that fixed before posting more tuts here.
|
|
|
|
![]() ![]() |
Similar Topics
|