dotkpay Posted July 27, 2011 Share Posted July 27, 2011 Hello, How do I use a session variable within function. In otherworldly how do I get to echo a session variable by calling a function? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/243004-using-session-vars-in-function/ Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 function callSession(){ print $_SESSION['ex_name']; } ?? Quote Link to comment https://forums.phpfreaks.com/topic/243004-using-session-vars-in-function/#findComment-1248098 Share on other sites More sharing options...
trq Posted July 28, 2011 Share Posted July 28, 2011 Functions should not rely on global vars. You should pass the value into the function: function foo($name){ echo $name; } foo($_SESSION['ex_name']); Quote Link to comment https://forums.phpfreaks.com/topic/243004-using-session-vars-in-function/#findComment-1248286 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.