Help - Search - Members - Calendar
Full Version: Create A Flat-file Shoutbox
Zymic Webmaster Forums > Zymic Free Web Hosting > Tutorials
nitsuarox
okay so step 1
create a file called form.php and insert the code:
CODE
<?php
if ($_GET['name'] == "") { echo "No name  <a href=# onClick=history.back()>BACK</a>"; }
if ($_GET['mess'] == "") { echo "No message  <a href=# onClick=history.back()>BACK</a>"; }
if  (($_GET['name'] != "") && ($_GET['mess'] != "")) {
$a=$_GET['name'];
$b=$_GET['mess'];


$stringData = "$a|$b\n";

$replaced = ereg_replace("<[^>]*>","",$stringData);

$tfile = 'shouts.txt';
if (file_exists($tfile)) {
$file = file($tfile);
$fp = fopen("$tfile", "w+");
fwrite($fp,$replaced);
if (is_array($file)) {
while (list(, $line) = each($file)) {

fwrite($fp, $line);
}
}
}
fclose($fp);
echo "OK  <a href=shout.php?page=0>BACK</a>";
}
?>



and cmod it to 777

now create a file called shoutbox.php
and insert:
CODE
<?php
$datafile=file("shouts.txt");
$cel1="#E9EDF8";
$cel2="#D2E4F2";
$entrate=15;
$azz=$_GET['page'];
$inizio=$_GET['page']*$entrate;
$fine=$inizio+$entrate;
$s=sizeof($datafile);
if ($_GET['page'] == "") { $i=0; }
if ($_GET['page'] != "") { $i=$inizio; }
?>
<HTML><HEAD><TITLE></TITLE>
<TABLE style="BACKGROUND-COLOR: #c0cbeb; border-collapse:collapse" cellSpacing=0 cellPadding=0 width="100%" border=0 bordercolor="#111111">
<TR>

<TABLE cellSpacing=1 cellPadding=2 width="100%" border=0>
<TR>
<TD align=middle width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="90%" style="border-collapse: collapse">
<?php
while (($i <= $fine) && (explode("|",$datafile[$i]) != null)) {
$mop = explode("|",$datafile[$i]);
$number = $i;
$newtext = wordwrap($mop[0], 9, "\n", 1);
$newtext1 = wordwrap($mop[1], 15, "\n", 1);
$newtext1 = ereg_replace(":)","<img src=smiles/smile.gif alt=\":)\" />", $newtext1);
$newtext1 = ereg_replace(":D","<img src=smiles/bigsmile.gif alt=\":D\" />", $newtext1);
$newtext1 = ereg_replace(":p","<img src=smiles/tongue.gif alt=\":p\" />", $newtext1);

if($number & 1) {
echo "<tr><td width=100% bgcolor=$cel1><b>$newtext </b>-- $newtext1 </td></tr>";
}
else {
echo "<tr><td width=100% bgcolor=$cel2><b>$newtext </b>-- $newtext1 </td></tr>";
}
$i++;
}
?>
<tr><form method="GET" action="form.php">
<td align="center">
<center>for smiles type :) or :D or :p</center>
<p align="left"><font face="Verdana" size="2">Name:</font><font face="Verdana"><input type="text" name="name" maxlength="10" size="11"></font></td>
</tr>
<tr>
<td align="center">
<p align="left"><font size="2" face="Verdana">Mess:</font><font face="Verdana"><input type="text" name="mess" maxlength="100" size="11"> </font></td>
</tr>
<tr><td align="center"><font face="Verdana">
<input type="submit" value="Submit" name="B1" style="float: left"></font></td></tr>
<tr><td width="20%" bgcolor="#C0CBEB" align="center"><font face="Verdana" size="2">

<?php
if (($_GET['page'] == "0") && ($s > $entrate)) { echo "     <a href=?page=1>>> 1</a>      "; }
if ((($_GET['page'] != "") && ($_GET['page'] != 0) && ($s > $fine))) { $azz2=$azz-1; $azz++;  echo "     <a href=?page=0>Start</a>     <a href=?page=$azz2><< $azz2</a>      <a href=?page=$azz>>> $azz</a>     "; }
if ($fine >= $s) { $azz2=$azz-1; echo "     <a href=?page=0>Start</a>          <a href=?page=$azz2>$azz2 <<</a>      "; }
?>
</font></td></tr></table></FORM></TD></TR></TBODY></TABLE></BODY></HTML>

now create a blank file called shouts.txt and cmodd it to 777
there you are finished for a demo go to http://ymcodes.zzl.org/dev/YMshout/ymshout.php
to download go to http://www.ymcodes.zzl.org
Alex
Ugh, I really think you should learn a bit more before writing tutorials. Several problems I noted on a quick read:
  • Short tags (<?) used instead of "<?php", not all servers have short tags enabled - so this is quite a big problem
  • You do know about indentation, right? That code is incredibly messy, and has little to no structure. Look at other code extracts to see how much cleaner code can be
  • Settings the $_GET variables to $a and $b, two issues with this: firstly it wastes memory, there's no real reason to reassign them at all; and secondly how do $a or $b give you any indication of what the variables store? They're terrible names for variables. $name or $message, or really anything would be better
  • Only one bit of sanitation, you've stripped <*>, but you haven't stopped the first "<", which can cause problems, and you also allow line breaks (%0A in the URL query string) which will cause issues
  • The logic in your pagination appears to be flawed, it gives me a link to ?page=-1 and continues to decrement. Scrap it and start again.
  • Your HTML is fairly awful too, you don't close the <head> tag, you miss out the doctype and encoding information... it really does need a lot of work

Now, bear in mind I haven't looked at all of it, so there are probably more issues.
desimasti
thanks for the shoutbox tutorial, and yah it really need alot of work if you need help working on it just reply here i will try my best to help you.
demented_goose
QUOTE(Alex @ Jan 6 2008, 03:54 AM) *
Ugh, I really think you should learn a bit more before writing tutorials. Several problems I noted on a quick read:
  • Short tags (<?) used instead of "<?php", not all servers have short tags enabled - so this is quite a big problem
  • You do know about indentation, right? That code is incredibly messy, and has little to no structure. Look at other code extracts to see how much cleaner code can be
  • Settings the $_GET variables to $a and $b, two issues with this: firstly it wastes memory, there's no real reason to reassign them at all; and secondly how do $a or $b give you any indication of what the variables store? They're terrible names for variables. $name or $message, or really anything would be better
  • Only one bit of sanitation, you've stripped <*>, but you haven't stopped the first "<", which can cause problems, and you also allow line breaks (%0A in the URL query string) which will cause issues
  • The logic in your pagination appears to be flawed, it gives me a link to ?page=-1 and continues to decrement. Scrap it and start again.
  • Your HTML is fairly awful too, you don't close the <head> tag, you miss out the doctype and encoding information... it really does need a lot of work
Now, bear in mind I haven't looked at all of it, so there are probably more issues.


Seems to me a little praise would be nice. Now i'm no coder and in all honesty i havent got a clue when it comes to PHP but surely even if this guys coding is a bit of a mess, even if it doesn't work in fact, he has attempted to put a valid tutorial in your tutorial section.

Would it not be a good idea to help him sort out the problems with his coding rather than just shooting him down? I can't imagion many people contributing to this section if whenever a mistake is made they are basically told they are stupid.
Alex
In some areas the fact that they tried is more important, but when you're teaching - it should be as perfect as possible. It's tutorials like these which end up teaching the next generation of programmers bad habits when they're starting up - and the main reason that I now advise everyone to avoid online tutorials entirely apart from a few sites I can vouch for.

Perhaps I was a bit harsh, but it still had to be said, because otherwise people will think this is how PHP should be written. When he's got some more experience, then I'd love to see some tutorials from him, but as it stands he's best off not writing any.

Just my opinion.
demented_goose
Yeah i understand what you're saying and i agree with you, I just think there are ways and means of telling people. Anyhoo, no harm done smile.gif
nitsuarox
I changed the short open tags and soon I will submit a better version of the

p.s. v2.0 is released on http://www.ymcodes.zzl.org
Evan
This tutorial works, but it is very badly coded. And there are already way too many poorly coded tutorials like this out there, guiding newbie php-developers in the wrong direction.

If you wanna be a serious php developer i suggest you read a book or two on PHP (especially try looking into OOP), books are the best way IMO to learn any programming language.

Sorry if that was a bit harsh, but you still have some learning to do before you can write tutorials mate!
arithm
http://arithm.99k.org/ <~~ That's ok?
nitsuarox
woah very nice!!!!!!!
arithm
hi! Thanks nitsua very much ^^, Good job smile.gif
nitsuarox
If you have any feature requests please tell me
arithm
Can you insert time in shoutbox ?

Ex:
QUOTE
Name ( time ): Mess
------------------------------
Ari ( 21:00 - 15/10/08 ): Mess for another


^^,
nitsuarox
the nect version (3.0) wich is a huge upgrade will, yes
The next version is also uses ajax happy.gif
arithm
waoo... when? harry ^^!!! luv your job :-*
Pioni-Sensei
It Should Work I Guess, If the permissions were set, and the files / folders existed/ could be made

fix it please.....
Jacob
Thanks for the attempt. Although you should remember to have good coding "manners" as Alex mentions above.

Jacob.
nitsuarox
Yeah I made this tutorial poorly buuuut the version on my site is better
zeeshan.khan
Hey anybody seen his site, it looks great,
nitsuarox can u please teach us how to achieve the functionality similar to ur site smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.