/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Let user change a constant variable

I have a constant variable in a php page. Its a threshold variable. I have manually set it to an initial amount. However, the customer request a way to change the threshold when they see fit.

I know of one way to get this done: Store the values in a database and read it every time the script runs. I would rather not do this.

Is it a good idea to write the value to a config file and read that. Is it a bad idea to write directly to the php file?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscJun 25.2009 — Sounds like you should be using sessions to keep track of this variable.
Copy linkTweet thisAlerts:
@kurbyauthorJun 25.2009 — Not quite. This change isn't based on the visitor. I want to be to let the customer change the variable so it affects all future visitors.
Copy linkTweet thisAlerts:
@SyCoJun 25.2009 — Giving user access to your server isn't bad but it requires you validate data to be sure it's in the format you expect and sanitize it in case an attack is attempted.

Either a file or data base would work just fine for what you need to do. Files solutions could be a simple txt file or an ini, this is handy for that kind of thing. http://us2.php.net/manual/en/function.parse-ini-file.php but file() would be just as easy.
Copy linkTweet thisAlerts:
@kurbyauthorJun 25.2009 — The way to edit this file would be with an fwrite?
Copy linkTweet thisAlerts:
@SyCoJun 25.2009 — Lots of tutorials out there.
Copy linkTweet thisAlerts:
@kurbyauthorJun 25.2009 — My question wasn't how to use fwrite, it was if this was the best or only way to edit an ini file.

Thanks.
Copy linkTweet thisAlerts:
@SyCoJun 25.2009 — You could create an ini file, read it into an array, change the array value, then overwrite it back. You can use SQLite too if your sever supports it.
×

Success!

Help @kurby spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...