mewhocorrupts Posted August 7, 2006 Share Posted August 7, 2006 I'm creating a site that utilizes the $_SESSION global heavily. I understand, in general, what it takes to make proper use sessions, insomuch as initialization, registering variables, and then assigning them. My question lies in whether or not it is possible, and if so, safe from a security point of view, to call a function from an included file that uses values stored in the user's session.For example:[code]<?phpsession_start();// Here we have some DB work, but the final product is the index of the user's record in MySQL...$ret = setLoginDBVars($index);?>[/code]And in the included file:[code]<?phpfunction setLoginDBVars($uid){ $db = new mysqli($GLOBALS['DB_SERVER'],$GLOBALS['DB_USER'],$GLOBALS['DB_PASS'],$GLOBALS['TBL_USERS']); $dbq = "SELECT "; // I'll have to get this from the DB structure. $res = $db->query($dbq); $row = mysqli_fetch_array($res, MYSQLI_ASSOC); foreach($row as $key => $val) { session_register($key); // Register $key (col name) with the session. $_SESSION[$key][$val]; // Dump all values into session global. } return true;}?>[/code]I don't have the database set up yet on my host, so the SELECT statement in the above code is obviously invalid. This is also the reason that I haven't live-tested yet to see the errors. In any case, will this be a valid function? Link to comment https://forums.phpfreaks.com/topic/16747-functions-and-_session/ Share on other sites More sharing options...
trq Posted August 7, 2006 Share Posted August 7, 2006 Yes. It is perfectly exceptable code and in fact even good practice to break your code into functions. Are you aware however the [i]session_register[/i] has long been deprictaed and unless your running a pretty old version of php is no longer required? Link to comment https://forums.phpfreaks.com/topic/16747-functions-and-_session/#findComment-70434 Share on other sites More sharing options...
mewhocorrupts Posted August 7, 2006 Author Share Posted August 7, 2006 [quote author=thorpe link=topic=103225.msg410952#msg410952 date=1154914012]Yes. It is perfectly exceptable code and in fact even good practice to break your code into functions. Are you aware however the [i]session_register[/i] has long been deprictaed and unless your running a pretty old version of php is no longer required?[/quote]I was actually not aware of that. Thanks for the info, I'll drop it from my code.Much appreciated. Link to comment https://forums.phpfreaks.com/topic/16747-functions-and-_session/#findComment-70730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.