babaz Posted November 2, 2010 Share Posted November 2, 2010 i have created an object in one page. it has a submit button which upon clicking opens a new page. is it possible to access that created object and its data members in that second page? here is the code for creating the object in the first page. $viewcart = new Cart(); $viewcart->GetProductCart($user); Quote Link to comment https://forums.phpfreaks.com/topic/217611-access-an-object-created-in-one-page-in-another-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2010 Share Posted November 3, 2010 You need to use a session variable, either directly - // class definition here ... session_start(); $_SESSION['viewcart'] = new Cart(); $_SESSION['viewcart']->GetProductCart($user); Or copy to/from a session variable - // class definition here... session_start(); // need for any session variable reference $viewcart = new Cart(); $viewcart->GetProductCart($user); ... $_SESSION['viewcart'] = $viewcart; // copy the object to a session variable in code or use a class destructor // second page // class definition here... session_start(); $viewcart = $_SESSION['viewcart']; // copy back on the second page The class definition must exist before the session_start() statement so that the object can be recreated from the session data. Quote Link to comment https://forums.phpfreaks.com/topic/217611-access-an-object-created-in-one-page-in-another-page/#findComment-1129712 Share on other sites More sharing options...
babaz Posted November 3, 2010 Author Share Posted November 3, 2010 thanks a bunch........works fine! Quote Link to comment https://forums.phpfreaks.com/topic/217611-access-an-object-created-in-one-page-in-another-page/#findComment-1129719 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.