View Full Version : Just a general question about variables
davehaz
04-11-2005, 12:16 AM
if you create a variable $sample and assign it a value of some kind, when does that variable go away?
also if you use a variable in a form and then $sample = $_Post[
sample'];
can you use the variable on other pages?
will the value stay the same until new input is entered?
thanks.
Fou-Lu
04-11-2005, 04:08 AM
I don't understand your question. Variables don't go from page to page by themselves, you need to find a way to pass them. The easiest ways are to use includes or sessions. Once the page is done, and the user browses to the new page, $sample is gone; as is $_POST['sample']; unless you specify them to pass.
Hi! H R U.
Its very easy to use variables in any form of site. If u want to get the value of one variable on the other page, u can do it by multiple ways.E.g. By using sessions, By using POST method, By using Hyperlinks. Now u have to decide which one suits ur requirements.
By using POST Method.
For example, u r using a textbox and u r getting its value on the other page. U have to keep this textbox into a form and the Action of this form will be the name of that form in which u r getting value and the method will be POST.
By using Sessions.
First u start the session as 'session_start()' and then register ur session as '$_SESSION['OnWhichURImplementingSessions'] = $variablehavingvalue'. Now u can use it as $variablehavingvalue=$_SESSION['OnWhichURImplementingSessions']; anywhere in ur site.
By using Hyperlink.
U send a variable with value by using a Query String attached with a Hyperlink as <a href='operations.php?action=enable. Now u can get the value of action(variable) on the operations.php form by using GET method as $action = $_GET['action'].
Regards,
Aamir.
God helps those who help themselves!
Bye. :thumbsup:
davehaz
04-11-2005, 04:07 PM
so when using sessions, you can assign variables and use they will stay static(remain unchanged) until they are modified, on any page of the website? If that is what Aamir was saying then that will work for me.
Thank you very much!
dave :)
Fou-Lu
04-11-2005, 05:02 PM
Yes, sessions are my personal recommendation for passing variables as well, both the query string and the post methods are alterable, while sessions are not. Once you set the variable, it will remain the same until modified. That is probably what you are looking for.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.