voip03 Posted August 15, 2011 Share Posted August 15, 2011 session register VS $_SESSION[] Which is best method? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/ Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 session_register has long been deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257591 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 15, 2011 Share Posted August 15, 2011 $_SESSION[]; session_register is a deprecated method thus is wont really be a good thing for the server. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257594 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 Thank you ZulfadlyAshBurn "Won’t really be a good thing for the server" Means security issues or slow down the server? Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257597 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 Instead of this <? session_register(USER_NAME); $_SESSION['USER_NAME']=$username; ?> I can write the code like this? <? $_SESSION['USER_NAME']=$username; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257598 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 15, 2011 Share Posted August 15, 2011 there would be errors if your server were to upgrade to PHP 5.3> they might be errors. // you will need session_start() session_start(); $_SESSION['USER_NAME']=$username; Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257603 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 so the best way is <? $_SESSION['USER_NAME']=$username; ?> thank you for your advice. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257607 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 15, 2011 Share Posted August 15, 2011 yeap Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257608 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 This code works. I can echo it. <? $username='HelloJay'; $_SESSION['USER_NAME']=$username; echo $_SESSION['USER_NAME']; ?> BUT this code dose not ? <? $username='HelloJay'; $_SESSION['USER_NAME']=$username; echo $_SESSION['USER_NAME']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257610 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 15, 2011 Share Posted August 15, 2011 firstly use full <?php not the shortcut <?. and you never start the session <?php session_start(); $username='HelloJay'; $_SESSION['USER_NAME']=$username; echo $_SESSION['USER_NAME']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257611 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 '<?' use it for quick coding and thank you 4u advice. I have learn more about session today. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257615 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 15, 2011 Share Posted August 15, 2011 <? is a bad practice. no prob. mark topic as solved its my honour to help people Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257621 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 session register session register returns Boolean type output session_register() is a php function used to register variables with the current session it will work only when register global is turned on in php.ini configuration file $_SESSION[] $_session returns string $_SESSION[] is a super global array SESSION works in both case whether register_global is disabled or enabled Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257622 Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 Actually. <?= is making something of a comeback ( not <? though) as a shortcut for <?php echo In 5.4: <?= is now always available regardless of the short_tags setting (Rasmus) This is good news IMO as it helps tidy the code used in allot of frameworks default view scripts. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257623 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 Actually. thorpe <?= is making something of a comeback ( not <? though) as a shortcut for <?php echo What is the best way? Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257633 Share on other sites More sharing options...
trq Posted August 15, 2011 Share Posted August 15, 2011 It is still best to be avoided for now. It'll be a long time before 5.4 is the standard. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257637 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Author Share Posted August 15, 2011 I take it this is the best method <?php echo “I’m a lumberjack.”; echo “And I’m okay.”; ?> thank you. Quote Link to comment https://forums.phpfreaks.com/topic/244821-session-register-vs-_session/#findComment-1257639 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.