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 :/
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 :/