Page 1 of 1

'updating' variables on files

Posted: Tue Jul 04, 2006 11:27 am
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

Posted: Tue Jul 04, 2006 12:41 pm
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.