How to read and write to a 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
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

How to read and write to a file?

Post by kaisellgren »

I have made login screen, but when the admin has logged, I want that there is change password option. It stores password in php file. How to read from it and how to write to php?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Just like from a regular file.

Use fopen() (and the rest of 'em), file() or file_get_contents() to read the file and fwrite() to write.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you should really look at using a database. its sooo much easier to use and whatnot
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

Okay. I have made a mysql database. My admin and password are stored there. But how the php file knows the mysql database name, password and so on...? This script is meant for many users so It must store the mysql connection settings in a file, but then anyone can access it, right?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

kaisellgren wrote:It must store the mysql connection settings in a file, but then anyone can access it, right?
No. Make it a php file that you always include, or better yet, user ezSQL.
As the name states, it's easy to use.
Post Reply