Problem Displaying Contents of File

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChipChamp
Forum Newbie
Posts: 13
Joined: Sun May 20, 2007 8:40 pm

Problem Displaying Contents of File

Post by ChipChamp »

I have a file which lets you make a name and a password in a text file, and what does work is that when you click the form its action is the following script and adds the name and password to the file. Now, the problem is that when I try to display the contents of $members[0] or $name[$i][0] or any other variable that I got from the file, instead it displays something like Resource id #1. How can I fix this? If you have any questions, feel free to ask.

Code: Select all

<?php

$filename = "members.txt";

$newmember = "";

$memberfile = fopen($filename, "r+");

$members = explode("||", $memberfile);

fclose($memberfile);

echo $members[0];

for ($i=0;$i<100;$i++) {
 $names[$i] = explode("^^", $members[$i]);
}

for ($i=0;$i<100;$i++) {
 if ($_POST["name"] == $names[$i][0]) {
  $already = 1;
 }
}

if ($_POST["name"] != "" && $_POST["pass"] && $already != 1) {
 $newmember = $_POST["name"]."^^".$_POST["pass"]."||";
 $file = fopen("members.txt", "a+");
 fputs($file,$newmember);
 fclose($file);
 echo "Your account has been successfully made.<br />";
}
else {
 echo "Your account has failed to be made. Please try again.<br />";
}

for ($i=0;$i<100;$i++) {
 echo "Name:".$names[$i][0]."<br />";
 echo "Password:".$names[$i][1]."<br /><br />";
}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

fopen() returns a file handle, not the contents of the file.
Take a llok at http://de2.php.net/fread and http://de2.php.net/file_get_contents
ChipChamp
Forum Newbie
Posts: 13
Joined: Sun May 20, 2007 8:40 pm

Post by ChipChamp »

Thanks! That worked. :)
Post Reply