underthefake Posted December 12, 2010 Share Posted December 12, 2010 I want to include a variable (for example an object $user) in each PHP page. Previously I declared $var in an include file then included that file in every page, however it generates an error in Zend Studio and it's also not very good programming style. I want to know how I can do it any other way. I was thinking of using constants but I don't know if constants should be used for this purpose and also I do not think constants can be defined as objects. Thank you very much for your help. Link to comment https://forums.phpfreaks.com/topic/221412-how-do-i-include-a-variable-in-each-php-page/ Share on other sites More sharing options...
litebearer Posted December 12, 2010 Share Posted December 12, 2010 using sessions and session variables you can 'carry' variable(s) to multiple pages http://www.tizag.com/phpT/phpsessions.php Link to comment https://forums.phpfreaks.com/topic/221412-how-do-i-include-a-variable-in-each-php-page/#findComment-1146281 Share on other sites More sharing options...
underthefake Posted December 12, 2010 Author Share Posted December 12, 2010 using sessions and session variables you can 'carry' variable(s) to multiple pages http://www.tizag.com/phpT/phpsessions.php I have read online that large objects in the session will impact performance greatly. My objects will be quite large so I don't think using sessions will be the best. Link to comment https://forums.phpfreaks.com/topic/221412-how-do-i-include-a-variable-in-each-php-page/#findComment-1146285 Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 if you don't want to store objects in sessions, store them in a database table and store the row identifier in a session var. Link to comment https://forums.phpfreaks.com/topic/221412-how-do-i-include-a-variable-in-each-php-page/#findComment-1146289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.