κατασκευή minichat

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
mat978
Δημοσιεύσεις: 6
Εγγραφή: 28 Ιουν 2010 01:48

κατασκευή minichat

Δημοσίευση από mat978 » 28 Ιουν 2010 02:06

Παραθέτω τον παρακάτω κώδικα που είναι για κατασκευή minichat σε site:

<?

$latest = $DOCUMENT_ROOT . "htdocs/minichat2.latest";
$archive = $DOCUMENT_ROOT . "htdocs/minichat2.archive";
$size = 20;
$nick_size = 20;
$message_size = 256;
$max_word_size = 20;

?>

<table width="120" align="center" border="0">
<tr>
<td>
<p align="center">
<font face="arial,sans-serif"><b><a href="http://www.jibble.org/chatbox.php">minichat 2</a></b></font>
</p>
<p align="center">
<form name="minichat_form" method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>">
<font face="arial,sans-serif" size="2">
<input type="hidden" name="minichat_md5" value="<? if (isset($minichat_message)) {echo md5($minichat_message);} ?>">
Nick:<br>
<input type="text" name="minichat_nick" maxlength="<? echo $nick_size; ?>" size="15" style="font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 10px"><br>
Message:<br>
<textarea name="minichat_message" cols="16" rows="3" style="font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 10px"></textarea><br>
<input type="submit" name="minichat_submit" value="Submit">
</font>
</form>
</p>
<p>
<font face="arial,sans-serif" size="1">

<?

// Check to see if the user is trying to post something.
if (isset($minichat_md5) && isset($minichat_nick) && isset($minichat_message)) {

// Replace any new line stuff with a space.
$nick = strtr($nick, "\r\n", " ");
$message = strtr($message, "\r\n", " ");

// Trim leading and trailing whitespace where necessary and remove slashes.
$nick = trim(stripslashes($minichat_nick));
$message = trim(stripslashes($minichat_message));

// Only proceed if the md5 hash of message is not repeated.
if (md5($message) != $minichat_md5) {

// Only proceed if the user actually filled in both fields.
if (strlen($nick) > 0 && strlen($message) > 0) {

// If the fields are too long, then chop them to the limits.
if (strlen($nick) > $nick_size) {
$nick = substr($nick, 0, $nick_size);
}
if (strlen($message) > $message_size) {
$message = substr($message, 0, $message_size);
}

// Remove new line characters from the input.
$nick = str_replace("\n", " ", $nick);
$message = str_replace("\n", " ", $message);

// Enforce the maximum word size by breaking up $message into lines.
$message = preg_replace("/([^\s]{20})/", "$1\n", $message);

// Now we can encode the nick and message into HTML.
$nick = htmlentities($nick);
$message = htmlentities($message);

// Now replace the new line characters in $message.
$message = str_replace("\n", "<br>", $message);

// The IP address of the poster, web cache or whatever.
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("j M Y - G:i:s T");

// Check to see if the 'latest' and 'archive' files exist and can be written to.
if (!is_writable($latest) || !is_writable($archive)) {
// Touch both files.
touch($latest);
touch($archive);
if (!is_writable($latest) || !is_writable($archive)) {
exit("$latest or $archive is not writable. Please check your permissions and try again.");
}
}

// Read every line of the 'latest' file into an array.
$lines = file($latest);
$bottom_index = count($lines);

// Note that each entry takes up 4 lines.
$line_ip = "<!-- $ip -->\n";
$line_nick = "* <font color=\"#9999ff\">Posted by $nick\n";
$line_time = "on $time</font><br>\n";
$line_message = "$message<br><br>\n";

$entry = $line_ip . $line_nick . $line_time. $line_message;

$already_posted = 0;
for ($i = 3; $i < $bottom_index; $i += 4) {
if ($lines[$i] == $line_message) {
$already_posted = 1;
break;
}
}

if ($already_posted == 0) {
// Now rebuild the 'latest' file.
// Start by entering the new entry at the top.
$out = fopen($latest, "w");
fwrite($out, $entry);

// Then write all other entries except the oldest.
if ($bottom_index >= $size * 4) {
$bottom_index = $size * 4 - 4;
}
for ($i = 0; $i < $bottom_index; $i++) {
fwrite($out, $lines[$i]);
}
fclose($out);

// Also append the entry to the archive file.
$out = fopen($archive, "a");
fwrite($out, $entry);
fclose($out);
}
else {
// This avoided a "probably accidental" repost.
}

}
else {
echo "<font color=\"red\">You must fill in both fields</font><br><br>";
}
}
else {
// This avoided a deliberate repost, maybe we should say something?
}


}

// include the latest comments on the page.
if (file_exists($latest)) {
include($latest);
}

?>

</font>
</p>
</td>
</tr>
</table>




και ας μου λύσει κάποιος την απορία γιατί δεν λειτουργεί; Γράφω ένα μήνυμα και πατώντας Submit εξαφανίζονται τα γράμματα και δεν κάνει τίποτα άλλο.

Άβαταρ μέλους
fafos
Script Master
Δημοσιεύσεις: 6231
Εγγραφή: 30 Νοέμ 2004 03:09

κατασκευή minichat

Δημοσίευση από fafos » 28 Ιουν 2010 03:45

auto to prama eina arxaio file mou!!

1. feiakse 2 KENA arxeia me to notepad me titlous:

latest.txt kai archive.txt

kai anevase ta sto site se kapoion fakello..

an einai yparkto site se server kai oxi local sto pc sou prepei na doseis ston fakelo ton arxeion kai sta arxeia CHMOD= 777


2. stis protes grammes koita na einai sosto to path:

Κώδικας: Επιλογή όλων

$latest = $_SERVER&#91;'DOCUMENT_ROOT'&#93; . "test/latest.txt";
$archive = $_SERVER&#91;'DOCUMENT_ROOT'&#93; . "test/archive.txt";
ego edo exo valei ta 2 arxeia se enan fakello me titlo test.. esy ta vazeis se opoion fakello thes kai allazeis ton titlo sta paths..

3. vres auto (einai kato apo ton kodika ths formas):
<?

// Check to see if the user is trying to post something.

kai amesos meta vale auta:

Κώδικας: Επιλογή όλων

$minichat_md5 = $_POST&#91;minichat_md5&#93;;
$minichat_nick=$_POST&#91;minichat_nick&#93;;
$minichat_message=$_POST&#91;minichat_message&#93;;

den koitaksa katholou an einai asfales auto to prama... psakse kati pio kainourio..

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 1 επισκέπτης