how can i keep a variable constant in php only for the time when that particular page is being accessed.
also what is the scope of the define(“xxx”,0.0); Function in php.
I want to store a dynamic variable in php which can be constant as long as it is used by only one user.
can $_Session[]; can be used for this purpose?
Please help !
All global variables you define have a scope of the current script for the current visitor; they are destroyed as soon as the script finishes processing. The same applies to constants.
Sessions are specific to a visitor and are retained across page-loads / script executions by that same user. When they get destroyed depends on the mechanism you are using (file / database) and the configuration of the web-server. Without any setup / special configuration you will probably notice that your variables cease to exist if you don’t load or reload a page for about an hour.
Apart from sessions you can of course also use query strings to pass values around from one script (page-load) to another, but they will be visible to the visitor.