'updating' variables on files

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
Galadrix
Forum Newbie
Posts: 1
Joined: Tue Jul 04, 2006 11:19 am

'updating' variables on files

Post by Galadrix »

Hey there,

Begginer PHP coder here :-D and I was wondering if it was possible to fopen a file and change two variables inside of it.

The file that's included on the page has two variables I would like to change: $keystones and $puzzle1.

When a user solves a puzzle, they proceed to a 'solved' page. At that page, I would like to add a value to $keystones, as a reward and then mark $puzzle1 true, so the user cannot go back to the page and 'cheat' (keep increasing their keystone amount).

I have sorted out the file includes (I modified a login script that uses sessions... it takes the session variable $user and recalls that user's unique character file, if you will).

I have some experience with PHP and I have been looking around for some answer to my problems.

Thanks for any help,

~galadrix
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you situation sounds like you'd be better off using a database to track progression of a user through the timeline. If you're dead-set on using unique files however, I'd suggest you take a look at file_get_contents() and fwrite() to manipulate the files.

you should be able to use a simple str_replace() to change the var name once you have the file open.
Post Reply