phpretard Posted March 23, 2008 Share Posted March 23, 2008 I haven't done much with sessions but I am starting to tinker. Could someone please tell me the difference between to 2 below? session_register("FirstName"); $_SESSION['FirstName']=$FirstName; -Anthony Link to comment https://forums.phpfreaks.com/topic/97493-simple-session-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 23, 2008 Share Posted March 23, 2008 The first version only works when register globals are on, has been depreciated since php 4.2 in the year 2002, and has been completely eliminated in php6. The second version should be used in all current and new code. The second version also works since PHP 4.1.0, regardless of the register globals setting. Link to comment https://forums.phpfreaks.com/topic/97493-simple-session-question/#findComment-498834 Share on other sites More sharing options...
phpretard Posted March 23, 2008 Author Share Posted March 23, 2008 Thank you for clearing that up. With that info in place... What do you suggest I use to replace this statement below and how should I echo the var? I would ultimatly like to echo the var on evry page...but it isn't happening unless I set it on every page. If this question is deeper then I think can you point me towards a good tutorial in these regards? if(session_is_registered(FirstName)){ echo "?????"; } Thank you fir you help with this. Link to comment https://forums.phpfreaks.com/topic/97493-simple-session-question/#findComment-498840 Share on other sites More sharing options...
wildteen88 Posted March 23, 2008 Share Posted March 23, 2008 When you use sessions, make sure you call the session_start() function on every page that uses sessions, eg: <?php session_start(); // your code ?> Also to check if a session variable exists, use isset: if(isset($_SESSION['FirstName'])) { echo '$_SESSION[\'FirstName\'] exists'; } else { echo '$_SESSION[\'FirstName\'] does not exist'; } session_is_registered is also depreciated I believe. Link to comment https://forums.phpfreaks.com/topic/97493-simple-session-question/#findComment-498847 Share on other sites More sharing options...
phpretard Posted March 23, 2008 Author Share Posted March 23, 2008 Great advice. Thank you for your help! Link to comment https://forums.phpfreaks.com/topic/97493-simple-session-question/#findComment-498852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.