Karthickraj.s Posted February 10, 2010 Share Posted February 10, 2010 Hi Friends, I am new to PHP.I am having some small clarification whether we use a Global variable for accessing one variable value into another PHP file. Example : I will assign the Global variable value in index.php file. I want to get the stored value into index1.php. Is this possible to get the value in PHP?... Thanks in advance Karthick Quote Link to comment https://forums.phpfreaks.com/topic/191602-global-variable/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 You would need to use a session in order to preserve data between http requests - http://www.php.net/manual/en/book.session.php Quote Link to comment https://forums.phpfreaks.com/topic/191602-global-variable/#findComment-1009989 Share on other sites More sharing options...
Karthickraj.s Posted February 10, 2010 Author Share Posted February 10, 2010 Thanks for your reply. Those pages are separate I get the values using OOPs concepts. That means one common class file that having SET and GET function for the variable. in INDEX file i set the value of the variable in INDEX1 file i get the STORED value of the variable. with out using SESSION Is this Possible to make in PHP?. Quote Link to comment https://forums.phpfreaks.com/topic/191602-global-variable/#findComment-1009995 Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 Web servers are stateless. All resources created on any page request are destroyed when the request for that page has been serviced. The only connection between any two http requests is what the browser supplies. Sessions work by passing a unique session id between pages by the browser which is matched up with the corresponding session data file on the server. You can create an instance of a class in a session variable by causing the class definition to exist before the session_start() statement. <?php require 'your_class.php'; session_start(); if(!isset($_SESSION['some_object_name'])){ // create instance $_SESSION['some_object_name'] = new your_class(); echo 'object created<br />'; } else { echo 'object exists<br />'; } $_SESSION['some_object_name']->class_function(); echo $_SESSION['some_object_name']->class_variable; ?> Quote Link to comment https://forums.phpfreaks.com/topic/191602-global-variable/#findComment-1010004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.