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 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']; } ?? 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']); 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
Archived
This topic is now archived and is closed to further replies.