user6509972 user6509972 - 7 months ago 35
HTML Question

PHP Updatable Variable

I am working on a site that has a variable for the current year. This variable is used throughout the website. The variable needs to be manually updated every year in the middle of the summer. I want to allow the admin to update that variable but it seems wasteful to create an entire table for one value.

The site is written in php and so I was wondering, is there anyway to update a variable with PHP through a form or something like that?


you can use a file to persist the value.

see fopen to get a file handle (use the w+ flag)

see fwrite to write to the file

see fclose to close the file

(or use file_put_contents instead of these three)

then use file_get_contents to read the value as saved in the file.

Note also that date("Y") will give you the current year. it doesn;t really make sense to update something like a date manually.