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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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.