tomfmason Posted August 7, 2006 Share Posted August 7, 2006 I am starting to put alot of my backend processing into functions. So now I have a login script that I am wondering if I should start the session in the login script. Here we go.Here is a section of the process.php[code=php:0]function showProcess($process) { switch ($process) { case "login": include("functions.php"); array_pop($_POST); if (get_magic_quotes_gpc()) { $_POST= array_map('stripslashes', $_POST); } $username = mysql_real_escape_string(trim($_POST['username'])); $password = mysql_real_escape_string(trim($_POST['password'])); $mdpwd = md5($password); $login = checkUser(); if ($login == "true") { echo "You are now loged in"; }else{ echo "$login"; } break;[/code]and here is the checkUser function[code=php:0]function checkUser() { include("db.php"); global $username; global $mdpwd; $sql = sprintf("SELECT COUNT(*) AS `login_match` FROM `users` WHERE `username` = '%s' AND `password` ='%s'", $username, $mdpwd); $res = mysql_query($sql) or die(mysql_error()); $login_match = mysql_result($res, 0, 'login_match'); if ($login_match == 1) { $q = mysql_query("SELECT * FROM `users` WHERE `username` ='$username'") or die(mysql_error()); while ($rw = mysql_fetch_assoc($q)) { // I will set my session variables $_SESSION['whatever'] = $rw['whatever']; } $result = "true"; }else{ $result = "Your username and password do not match"; } return $result;}[/code]My question is this a good way of doing this or ? and where should I place the session start? Should it be in the function or at the begining of the functions.php. Thanks,Tom Quote Link to comment Share on other sites More sharing options...
corbin Posted August 7, 2006 Share Posted August 7, 2006 Begining of the file is where i put it... then again any file ive ever created using sessions starts like<?session_start(); Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Author Share Posted August 7, 2006 I know that but which one should I place the session_start in. Should it be the functions.php or the process.php or both. Does the session carry over into the function? Quote Link to comment Share on other sites More sharing options...
corbin Posted August 7, 2006 Share Posted August 7, 2006 are you including function.php?'Cause if you are just make sure session_start is above the include command in process.php Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Author Share Posted August 7, 2006 I guess I should not be lazy and test these things prior to posting..lolThanks for the helpTom Quote Link to comment 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.