How do I create a shared variable in PHP?

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
hanct
Forum Newbie
Posts: 2
Joined: Mon Jul 14, 2003 5:14 am

How do I create a shared variable in PHP?

Post by hanct »

I read some tutorials on variable in PHP, but none seem to talk about shared variable, variable that is shared among all clients....which is similar to the static variable found in JSP, where this variable is shared by all user.

No i dont want to use database, just wanna some way to create variable to hold some data to be shared by all users.

For example, I have a variable in php script:

$car=5;
$car++;
print($car);

If a user access this script, he will see the no.6 printed out. The next user access this script will see no. 7 and so on!!!!
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Use fwrite (if the your server allows it)
hanct
Forum Newbie
Posts: 2
Joined: Mon Jul 14, 2003 5:14 am

Ok! thanks!! But if i wanted to use just variable, not using

Post by hanct »

not using file, is it possible in PHP?
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

I wouldnt know how to retreive a variable from something else then a database or a file (..if its supposed to be passed on to other users).
Maybe someone else knowes?
ik
Forum Commoner
Posts: 34
Joined: Thu Jul 10, 2003 5:33 am
Location: Lancs Uni, UK
Contact:

Post by ik »

Sure, you ought to keep the value of your variable anywhere between succesive calls of you script. File seems to be the best and simplest solution.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

PHP does not offer application variables that are accessible to all users without using database or text file storage.

Mac
Post Reply