fopen() not working...!
Posted: Mon Oct 10, 2005 10:29 pm
Here's the deal right now. I've got one page (price.php) which I'm using for the password protection for the other page. Here's the code I use for that page.
I have the second page (obviously price_editor.php) that I'm using to read and write to a price list. I'm using "|" as a tokenizer in the file to seperate entries. Here is the code I have:
I can't get the page to load with opening the file. I've tried commenting out everything else in the php tags except the fopen() and fclose() function calls, but it still doesn't work with those. If I don't have file-related code running, then it works fine (for instance, echoing some text after validating the password). I have a text file called "mt102.txt" in the same directory as both of these pages as well. Any suggestions would be great, thanks!
Code: Select all
<html>
<head>
<title>Price List Editing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>Please enter password to unlock:</p>
<form name="password" method="post" action="price_editor.php">
<input type="text" name="password">
<input name="submit" type="button" value="Submit">
</form>
<p> </p>
</body>
</html>Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$password = $_POST['password'];
if ($password == "easy")
{
$filename = "mt102.txt";
$file = fopen($filename, "a+");
fseek($filename, 0);
$filesize = filesize($filename);
$text = fread($file, $filesize);
$fclose = ($file);
$count = 0;
$tracker = 0;
$arr = array();
$arrcounter = 0;
while ($count + 1 != $filesize)
{
$temp = substr($text, $count, $count + 1);
if $temp = "|" then
{
$arr[$arrcounter] = substr($text, $tracker, $count + 1);
$tracker = $count;
$arrcounter = $arrcounter + 1;
}
}
echo("Price for item 1 (current price is $arr[1])
<br>Price for item 2 (current price is $arr[2])
<br>Price for item 3 (current price is $arr[3])
<br>Price for item 4 (current price is $arr[4])
");
echo("testing");
}
else
{ echo("You are not authorized to view this page") ; }
?>
</body>
</html>