storing variables

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
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

storing variables

Post by jaymoore_299 »

What is the best way to store variables (that don't store any important data) in a file then access and modify them easily from any php script?

I was thinking of a file with a list of variables like this:

$var1='1';
$var2='2';
$var3='3';
..
..
$var7='7';

What if I had a program that only needs 2 variables, and with the need to change them right after using them?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i would store them in:
- a database... (application wide)
- a session... (user wide)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Don't store them in a flat file - too much overhead, security issues etc, use a database or a session like ~timvw suggested.

What are you going to use these variables for? Are they going to be:
  • valid and unique for a single users visit or,
  • 1 set of variables for all users or,
  • variables that apply to a user over multiple visits?
If the situation is the first I mentioned, I'd use sessions. If the situation is the 2nd, I'd use a database. If the situation is the 3rd, I'd use a database as well, although cookies might be able to work as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

Post by jaymoore_299 »

the variables are for internal use only. I need variables to keep track of things like, hit tracking, rotation of links, etc.

If I have 100 links and rotate 3 a day, I need a variable to store where I left off last so that all the links are evenly cycled through.
User avatar
Spaceboy
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 2:10 pm

Post by Spaceboy »

A database would be the easiest thing. Do you MySQL?
Post Reply