kvishnu_13 Posted June 10, 2007 Share Posted June 10, 2007 Hey, I was writing my login.php script, and instead of creating every session one-by-one, I tried to create a function that assigns all the sessions...but it doesn't work for some reason. I don't understand what the mistake is. The code is really simple... function gen_sessions($arr) { foreach ($arr as $k => $v) { $_SESSION['$k'] = "$v"; } } This function is later called in the login.php script itself, after all the validation is done using.... $row = mysql_fetch_array ($sql, MYSQL_NUM); gen_sessions($row); There are no errors, and the login process is also done, but I am not able to access the sessions(session_start() has been added). For example, later in a different page my program is not going through the if conditional: if((isset($_SESSION['11']))) I have a feeling that it is just some syntax error. Please help... Quote Link to comment https://forums.phpfreaks.com/topic/54927-setting-sessions-using-foreachwill-it-work/ Share on other sites More sharing options...
fert Posted June 10, 2007 Share Posted June 10, 2007 $_SESSION[$k]=$v; Quote Link to comment https://forums.phpfreaks.com/topic/54927-setting-sessions-using-foreachwill-it-work/#findComment-271660 Share on other sites More sharing options...
kvishnu_13 Posted June 10, 2007 Author Share Posted June 10, 2007 $_SESSION[$k]=$v; Hey fert, I tried that and various other combinations with the quotes and functions...still does not work. Are u sure there are no more errors? Thanks for the previous reply man. Does anyone else see an error?? __ kvishnu_13 Quote Link to comment https://forums.phpfreaks.com/topic/54927-setting-sessions-using-foreachwill-it-work/#findComment-271679 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.