...

View Full Version : Help - my PHP script is writing chinese characters into my index



Cbrams
01-23-2007, 12:33 PM
Okay, to sum up, I have to do a school project on PHP scripting, and we ere assigned to code a blog, using only PHP, so no mySQL soloutions. I am aware that this is screwing security, but we'll have to make do :P..

The thing is, I can't find an error in this script, but everytime I try to add a post, it posts useless chinese characters in my index file, and it doesn't seem to want to create a new file for the post either :/
EDIT: It does add a new post now :) -- still chinese char problem

This is the code:

<?php
if (isset($_POST['pass']))
{
$kode = $_POST['pass'];
$password = fopen("password.txt","r") or exit("Error #1");
$pass = fgets($password);
fclose($password);
if($kode==$pass)
{

$index = fopen("index.txt","a") or exit("Error #2");
$message = $_POST['tekst'];
$title = $_POST['title'];
$author = $_POST['author'];
$indexarray = explode("",$index);
$number = count($indexarray);
$number = $number + 2;
$title2 = " $title";
fwrite($index,$title2);
$filnavn = "blogpost/" . $number . ".txt";
touch($filnavn);
$file = fopen("$filnavn","w") or exit("Error #3");
$skriv = "<h3>$title</h3><br><p>Forfatter: $author</p><br><br><p>$message</p>";
fwrite($file,$skriv);
fclose($file);
fclose($index);
}
else {
echo "Kun for brugere";
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<h1>Bidrag til siden</h1>
<?php
$index = fopen("index.txt","r") or exit("Error #4");
$indexarray = explode("",$index);
$number = count($indexarray);
$number = $number + 1;
for($i=$number;$i>0;$i--) {
$file=fopen("blogpost/" . $i . ".txt","r") or exit("Error #5");
echo "<p>";
while(!feof($file))
{
echo fgets($file)."<br>";
}
fclose($file);
echo "</p>";
}
fclose($index);

?>

Which is recieved from this form:

<html>
<body>
<form action="read.php" method="post">
<h5>Titel:</h5><input type="text" name="title"><br>
<p>Forfatter:</p><input type="text" name="author"><br>
<p>Tekst:</p><br>
<textarea name="tekst" rows="6" cols="20"></textarea><br>
<p>Password</p><input type="password" name="pass">
<input type="submit" value="Post it!">
</form>
</body>
</html>

Any of you guys know a soloution to this :/?

For reference, it doesn't evene add the symbol I need :/

mlseim
01-23-2007, 01:44 PM
Right after <html> insert this line:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

See if that helps the output.

=========

Not creating a new file, but you get no errors?

Perhaps the directory you are writing to does not have
permissions set. CHMOD the permission of your directory to 777.

Cbrams
01-23-2007, 01:54 PM
Unfourtunatly, that didn't solve it :(.. However, it creates new files now, thank you :)

I've attached a picture of what it creates instead of the .. 1 and 2 I put there to test it..

mlseim
01-23-2007, 02:54 PM
See if you can use &pound; instead ...

Here's a list of special HTML characters ...

http://www.utexas.edu/learn/html/spchar.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum