Question:
PHP: How to retain a value in any variable accross pages?
Vinay
2007-10-09 02:58:20 UTC
Hi, I am new to PHP programming , how can I mantain a global variable which can be updated and read from any page of my website.For Example a user is member of many team (team_id) and after login to my website and selecting one of team ,I want to reuse the TEAM_ID in all other visited page and the variable value should change once user move to other team. I don't want to go with COOKIES as all browse doen't have enabled cookies.
Thanks,
Three answers:
Milamber [NL]
2007-10-09 03:07:33 UTC
Most people use sessions (however underneath the surface that does use a cookie to store the session id)



If you really don't wanna use that, you should pass the variable to the other pages by attaching them to the URL (HTTP-GET)



Your URL would look like this: http://somesite.com/page.php?team_id=114
barry p
2007-10-09 10:04:48 UTC
you can do it two ways. by either global variables or session variables.



to use assign $team_id to a value you can call it it following pages by



global $team_id



if you are using session you must start the page session_start()



then user $_SESSION[team_id]=$team_id;
Roop
2007-10-13 07:14:23 UTC
hi



You can user SESSION here also you can use the global



include a common files for all the pages



global $teamid



declare this in the header and use.



I'm not sure about this, better to use session



Regards

Roopesh


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...