cos.alpha Δημοσ. 3 Ιουνίου 2009 Δημοσ. 3 Ιουνίου 2009 Παιδιά χαιρετώ το φόρουμ και ζητώ τα φώτα σας. Βρήκα ένα script για ένα βιβλίο επισκεπτών (http://www.jemjabella.co.uk/scripts/bellabook) που θέλω να φτιάξω στο site μου και έχω το εξής πρόβλημα. Όταν βάζω ελληνικούς χαρακτήρες στα πεδία (όνομα, comments), δεν μπορώ να κάνω submit. Τα βγάζει ως σύμβολα. Μπορείτε να δοκιμάσετε στο http://www.c-andronis.gr/gb/index.php όπου, όπως θα δείτε, έχω κάνει προσπάθειες αλλά επι ματαίω. Δεν συνδέεται με βάση δεδομένων το guestbook οπότε δεν είναι πρόβλημα mysql. Επικοινώνησα με τον τύπο που έφτιαξε το script και μου είπε να βάλω 3 γραμμές κώδικα για να αναγνωρίζει utf-8 αλλά ούτε αυτό δεν έφτιαξε την κατάσταση. Επισυνάπτω το config.php και το sign.php ><?php //----------------------------------------------------------------------------- // BellaBook Copyright © Jem Turner 2004-2007,2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- require_once('prefs.php'); define("ENTRIES", "entries.txt"); define("TEMPENTRIES", "tempentries.txt"); define("IPBLOCKLST", "iplist.txt"); define("SPAMWDS", "spamwords.txt"); function cleanUp($text) { $text = trim(htmlentities(strip_tags($text), ENT_NOQUOTES, UTF-8)); return $text; } // break big words every 50 characters for layout preservation. function linebreaker($text) { $new_text = ''; $text_1 = explode('>',$text); $sizeof = sizeof($text_1); for ($i=0; $i<$sizeof; ++$i) { $text_2 = explode('<',$text_1[$i]); if (!empty($text_2[0])) { $new_text .= preg_replace('#([^\s .]{50})#i', '\\1 ', $text_2[0]); } if (!empty($text_2[1])) { $new_text .= '<' . $text_2[1] . '>'; } } return $new_text; } function doAdminHeader() { global $stylecolor; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>BellaBook Control Panel</title> <link href="<?php echo $stylecolor; ?>-stylesheet.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <p id="topnav"><a href="index.php">View the Guestbook</a> · <a href="admin.php">Admin Main</a> · <a href="logout.php">Logout</a></p> <?php } function doAdminFooter() { echo "\r\n</div>\r\n</body>\r\n</html>"; } // fix the blank lines in iplist/badwords/entries files function blanklinefix($inputfile) { ignore_user_abort(true); $content = file($inputfile); if (count($content) > 0) { $content = array_diff(array_diff($content, array("")), array("\r\n")); $newContent = array(); foreach ($content as $line) { $newContent[] = trim($line); } $newContent = implode("\r\n", $newContent); $fl = fopen($inputfile, "w+"); if (flock($fl, LOCK_EX)) { fwrite($fl, $newContent); flock($fl, LOCK_UN); } else { echo 'The file: '.$inputfile.' could not be locked for writing; the blanklinefix function could not be applied at this time.'; } fclose($fl); } ignore_user_abort(false); } function doWrite($file2open, $data, $writetype) { $file = fopen($file2open, $writetype) or die("ERROR: could not open ".$file2open); if (flock($file, LOCK_EX)) { fwrite($file, $data); flock($file, LOCK_UN); } else { exit("ERROR: could not lock ".$file2open); } fclose($file); } function sign_gbook($file, $entry) { // one of these days I really should really should re-write the whole lot and just use sorting functions $oldData = file_get_contents($file); doWrite($file, $entry, "w"); // write the new data doWrite($file, $oldData, "a"); // append the old data echo "<p>Thank you for signing the guestbook.</p>"; if ($file === TEMPENTRIES) echo "<p>Moderation is enabled, the guestbook owner will have to approve your message before it appears.</p>"; } function emoticonise($message) { global $smilies; $path_to_smilies = "smilies/"; if (isset($smilies) && $smilies == "yes") { $smiliesA = array( ':)' => 'smile.gif', ':D' => 'biggrin.gif', ':(' => 'sad.gif', ':P' => 'tongue.gif', ':o' => 'shocked.gif', ';)' => 'wink.gif', ); foreach ($smiliesA as $key => $value) { $message = str_replace($key, " <img src='".$path_to_smilies.$value."' alt='$key' title='$key' />", $message); } return $message; } else { return $message; } } function checkBots() { $isbot = false; $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot"); foreach ($bots as $bot) if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) $isbot = true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") $isbot = true; if ($isbot === true) { echo "<p>Safety checks indicate there's a high probability that you're a bot, and bots aren't allowed to submit links.</p>"; exit(include('footer.php')); } } function breakEmail($email) { $email = str_replace('.', 'DOTTY', $email); $email = str_replace('@', 'ATTIE', $email); $email = str_replace('-', 'DASHY', $email); $email = str_replace('_', 'SCORE', $email); return $email; } function fixEmail($email) { $email = str_replace('DOTTY', '.', $email); $email = str_replace('ATTIE', '@', $email); $email = str_replace('DASHY', '-', $email); $email = str_replace('SCORE', '_', $email); return $email; } if ($emailrequired == "yes") $req = "<small>(req.)</small>"; else $req = "<small>(not req.)</small>"; if ($showemail == "yes") $disp = " <small>(displayed)</small>"; else $disp = " <small>(not shown)</small>"; function countcontents($fileloc) { // why did I put this in? it's so redundant... if (filesize($fileloc) > 0) return count(file($fileloc)); else return 0; } blanklinefix(ENTRIES); blanklinefix(TEMPENTRIES); blanklinefix(IPBLOCKLST); blanklinefix(SPAMWDS); error_reporting(0); ?> ><?php //----------------------------------------------------------------------------- // BellaBook Copyright © Jem Turner 2004-2007,2008 unless otherwise noted // http://www.jemjabella.co.uk/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License. See README.txt // or LICENSE.txt for more information. //----------------------------------------------------------------------------- $show_form = true; $error_msg = NULL; if (isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] == "POST") { require_once('config.php'); if (isset($captcha) && $captcha == "yes") { session_start(); if(md5($_POST['captcha']) != $_SESSION['key']) { setcookie(session_name(), '', time()-36000, '/'); $_SESSION = array(); session_destroy(); include('header.php'); echo "<p>The text you entered didn't match the image, please <a href='sign.php'>try again</a>.</p>"; include('footer.php'); exit; } if (isset($_SESSION['key']) && isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-36000, '/'); $_SESSION = array(); session_destroy(); } } include('header.php'); // let's do some pattern matching on the IP to make sure this visitor is legit, not banned and not flooding $ipPattern = '/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i'; if (filesize(IPBLOCKLST) > 0) { $BlockedIPs = file(IPBLOCKLST); // loop through and trim, otherwise the IP filter doesn't work foreach($BlockedIPs as $key => $ip) $BlockedIPs[$key] = trim($ip); $iplist = '/(' . implode('|', $BlockedIPs) . ')/'; } if ($floodcontrol == "yes" && filesize(ENTRIES) > 0) { $open2check = file(ENTRIES); $expodelineone = explode(",", $open2check['0']); if ($_SERVER['REMOTE_ADDR'] == $expodelineone['4']) { echo "<p>Sorry, you can't sign the guestbook twice in a row.</p>"; exit(include('footer.php')); } } if (!preg_match($ipPattern, $_SERVER['REMOTE_ADDR']) || (isset($iplist) && preg_match($iplist, $_SERVER['REMOTE_ADDR']))) { echo "<p>Your IP is not valid or it has been banned, you cannot sign the guestbook.</p>\n\n"; exit(include('footer.php')); } // check to make sure it's not a known bot checkBots(); // check for links before we clean up so they don't get removed with strip_tags if (isset($allowlinks) && $allowlinks == "no" && (substr_count($_POST['comments'], 'http://') > 0 || substr_count($_POST['comments'], 'URL=') > 0)) { echo "<p>Your message contains URLs. To cut down on spam, the posting of URLs/links has been disabled. \n</p>"; exit(include('footer.php')); } // prepare spam words if (filesize(SPAMWDS) > 0) { $spamlist = file(SPAMWDS); // loop through and trim, otherwise the spam filter doesn't work foreach($spamlist as $key => $spamword) $spamlist[$key] = trim($spamword); $SpamWords = '/(' . implode('|', $spamlist) . ')/i'; } // check for javascript exploits/spam and clean up the data $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i"; foreach ($_POST as $key => $val) { if (isset($SpamWords) && preg_match($SpamWords, urldecode($val))) { echo "<p>Your message contains words in the spam list, please go back and remove references to obvious 'spam' material. \n</p>"; exit(include('footer.php')); } if (preg_match($exploits, $val)) { echo "<p>No meta injection, please. \n</p>"; exit(include('footer.php')); } $c[$key] = cleanUp($val); } // do some final checks $error_msg = NULL; if (!empty($c['human'])) { $error_msg .= "Spam detection tells me you're not human."; } elseif (empty($c['name']) || !ereg("^[A-Za-z' -]*$", $c['name']) || strlen($c['name']) > 12) { $error_msg .= "Name is a invalid: must not be blank, must have no special characters, must not exceed 12 characters."; } elseif ($emailrequired == "yes" && empty($c['email'])) { $error_msg .= "E-mail is a required field, please fill it in."; } elseif (!empty($c['email']) && !ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", strtolower($c['email']))) { $error_msg .= "The e-mail address that you provided is not valid."; } elseif ((!empty($c['url']) && $c['url'] != "http://") && !preg_match('/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(\d+))?\/?/i', $c['url'])) { $error_msg .= "The website address that you provided is not valid."; } elseif (empty($c['comments']) || strlen($c['comments']) < 10) { $error_msg .= "Your comment is too short."; } if ($error_msg == NULL) { $show_form = false; // let's make the data look nice and pretty $c['name'] = ucwords(strtolower($c['name'])); $c['email'] = strtolower($c['email']); $c['comments'] = str_replace("<br /><br /><br /><br />", "<br /><br />", preg_replace("/,(?! )/", ", ", preg_replace("([\r\n])", "<br />", $c['comments']))); if ($emailentries == "yes") { $subject = "New entry in guestbook ($title)"; $message = "Name: ".$c['name']." \r\n"; $message .= "E-mail: ".$c['email']." \r\n"; $message .= "Website: ".$c['url']." \r\n"; $message .= "Comments: ".$c['comments']." \r\n"; \r\n\r\n"; $message .= "-- ADMIN INFO -- \r\n"; $message .= "IP: ".$_SERVER['REMOTE_ADDR']." \r\n"; $message .= "Browser: ".$_SERVER['HTTP_USER_AGENT']." \r\n"; $message .= "Referrer: ".$_SERVER['HTTP_REFERER']." \r\n"; $message .= "Admin Panel: ".$admin_gburl."/admin.php \r\n"; if ($moderate == "yes") $message .= "\r\nYou will need to approve this entry for it to appear in your guestbook."; $headers = "From: ".$title." <$admin_email> \r\nReply-To: <$email>"; mail($admin_email,$subject,$message,$headers); } $entryformat = $c['name'].",".breakEmail($c['email']).",".$c['url'].",".$_SERVER['REMOTE_ADDR'].',"'.$c['comments'].'"'."\r\n"; if ($moderate == "yes") sign_gbook(TEMPENTRIES, $entryformat); else sign_gbook(ENTRIES, $entryformat); } } if (!isset($_POST['submit']) || $show_form == true) { require_once('config.php'); include_once('header.php'); function get_data($var) { if (isset($_POST[$var])) echo cleanUp($_POST[$var]); } ?> <p>Fill in your details in the form below. No HTML allowed.</p> <?php if ($error_msg != NULL) { echo '<p><strong style="color: red;">ERROR:</strong><br />'.$error_msg.'</p>'; } ?> <form action="sign.php" method="post"> <p class="hidden"> <input type="checkbox" name="human" id="human" /> <label for="human">Leave this unticked if you're human </label> </p> <p> <input type="text" name="name" id="name" value="<?php get_data("name"); ?>" /> <label for="name">Name</label> <br /> <input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /> <label for="email">E-mail</label> <?php echo $req . $disp; ?><br /> <input type="text" name="url" id="url" value="http://" /> <label for="url">Website URL</label> <br /> <textarea name="comments" id="comments"><?php get_data("comments"); ?></textarea> <label for="comments">Comments</label> <br /> <?php if (isset($captcha) && $captcha == "yes") { ?> <img src="captcha.php" alt="" style="margin-bottom: 2px;" /><br /> <input type="text" name="captcha" id="captcha" /> <label for="captcha">Numbers in Image</label> <br /> <?php } ?> <input type="submit" id="submit" name="submit" value="Submit" /> </p> </form> <?php } include('footer.php'); ?> Ελπίζω να βρούμε κάποια λύση. Ευχαριστώ εκ των προτέρων, Κωνσταντίνος
g_alex_stef Δημοσ. 3 Ιουνίου 2009 Δημοσ. 3 Ιουνίου 2009 Άνοιξε το αρχείο entries.php με notepad++ και άλλαξέ του κωδικοποίηση σε utf8. Σώστο και πες μας τι έκανες.
cos.alpha Δημοσ. 3 Ιουνίου 2009 Μέλος Δημοσ. 3 Ιουνίου 2009 Άνοιξε το αρχείο entries.php με notepad++ και άλλαξέ του κωδικοποίηση σε utf8. Σώστο και πες μας τι έκανες. g_alex_stef, ευχαριστώ για την άμεση απάντηση. Δεν υπάρχει αρχείο entries.php - μόνο entries.txt ...
fromaz Δημοσ. 3 Ιουνίου 2009 Δημοσ. 3 Ιουνίου 2009 Η χρήση της htmlentities είναι λάθος. Αυτό >function cleanUp($text) { $text = trim(htmlentities(strip_tags($text), ENT_NOQUOTES, UTF-8)); return $text; } κάντο έτσι >function cleanUp($text) { $text = trim(htmlspecialchars(strip_tags($text))); return $text; } Αν θες να επιτρέπεις ελληνικά ονόματα, πρέπει να διορθώσεις και τον αντίστοιχο έλεγχο >} elseif (empty($c['name']) || !ereg("^[A-Za-z' -]*$", $c['name']) || strlen($c['name']) > 12) { $error_msg .= "Name is a invalid: must not be blank, must have no special characters, must not exceed 12 characters.";
cos.alpha Δημοσ. 3 Ιουνίου 2009 Μέλος Δημοσ. 3 Ιουνίου 2009 fromaz, ευχαριστώ πάρα πολύ για την απάντηση. Γεγονός είναι ότι δεν μου βγάζει τα ελληνικά ως σύμβολα πιά () αλλά δεν με αφήνει να κάνω submit. Βγάζει, δηλαδή, το ίδιο μήνυμα λάθους [Name is a invalid: must not be blank, must have no special characters, must not exceed 12 characters.] αλλά πια τα ελληνικά είναι εντάξει. Η τελευταία οδηγία που μου δίνεις είναι απλά να αντικαταστήσω τον κώδικο στο sign.php με αυτό που παραθέτεις, όσον αφορά στον αντίστοιχο έλεγχο ή κάτι άλλο; Σε ευχαριστώ πόλύ και πάλι! You've made my day!
fromaz Δημοσ. 3 Ιουνίου 2009 Δημοσ. 3 Ιουνίου 2009 Το τρίτο κομμάτι κώδικα που παρέθεσα έχει να κάνει με το πρόβλημα του ονόματος που λες (σε πρόλαβα). Ο έλεγχος που κάνει το script, δεν επιτρέπει ελληνικά (utf-8) ονόματα. Αφαίρεσε το κομμάτι >|| !ereg("^[A-Za-z' -]*$", $c['name']) και θα είσαι περίπου ok. Λέω περίπου γιατί το 12 χαρακτήρες είναι εξίσου προβληματικό. Γενικά, ο τύπος που έφτιαξε το script δεν κατέχει το θέμα του utf-8. Υπάρχουν και άλλα λάθη, αλλά ένα-ένα μη μου πάθεις και τίποτα...
ΠάρηςΓ Δημοσ. 3 Ιουνίου 2009 Δημοσ. 3 Ιουνίου 2009 Απλά ο ελεγχος δεν ελεγχει ελληνικα γραμματα εαν καταλαβα καλά..Για αυτο παντα στα βγάζει λάθος
cos.alpha Δημοσ. 3 Ιουνίου 2009 Μέλος Δημοσ. 3 Ιουνίου 2009 Το τρίτο κομμάτι κώδικα που παρέθεσα έχει να κάνει με το πρόβλημα του ονόματος που λες (σε πρόλαβα). Ο έλεγχος που κάνει το script, δεν επιτρέπει ελληνικά (utf-8) ονόματα. Αφαίρεσε το κομμάτι >|| !ereg("^[A-Za-z' -]*$", $c['name']) και θα είσαι περίπου ok. Λέω περίπου γιατί το 12 χαρακτήρες είναι εξίσου προβληματικό. Γενικά, ο τύπος που έφτιαξε το script δεν κατέχει το θέμα του utf-8. Υπάρχουν και άλλα λάθη, αλλά ένα-ένα μη μου πάθεις και τίποτα... fromaz, έγραψες! Παρόλο που στο admin δεν μου βγάζει τους χαρακτήρες σωστά [άντε να το βρούμε τώρα αυτό...] στο frontend είναι όλα εντάξει. Όσον αφορά τώρα στα άλλα προβληματάκια, καθότι άσχετος με php, εννοείται πως δεν τα έχω εντοπίσει αλλά αν είναι σοβαρά, δώσε και σώσε που λένε. Έχω καλή κράση... Σε ευχαριστώ πάρα πολύ!
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.