sgiandhu Posted November 20, 2005 Share Posted November 20, 2005 Can someone please check over my DW generated syntax and let me know if I've got the bits all in the right place? I'm mostly concerned about the position of the cookie in relation to both the call for the secure site and the connection... <?php //made sure we go to the secure server include_once ('../igosecure.php'); //connect to the DB require_once('../Connect/myDB.php'); // save the username information for the login form if (isset($_POST['Login'])) { if (isset($_POST['storeprofile'])) { setcookie("UserName", $_POST['username'], time()+86400*30); } else { setcookie ("UserName", "",time()-43200); } } // *** Validate request to login to this site. session_start(); $loginFormAction = $_SERVER['PHP_SELF']; if (isset($accesscheck)) { $GLOBALS['PrevUrl'] = $accesscheck; session_register('PrevUrl'); } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "access"; $MM_redirectLoginSuccess = "https://www.mysite.com/others/theirpage.php"; $MM_redirectLoginFailed = "login.php?failed=true"; $MM_redirecttoReferrer = false; mysql_select_db($database_myDB, $myDB); $LoginRS__query=sprintf("SELECT username, password, m_access, memberID FROM members WHERE username='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $myDB) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'m_access'); //declare two session variables and assign them $GLOBALS['MM_UserName'] = $loginUsername; $GLOBALS['MM_UserID'] = mysql_result($LoginRS,0,'memberID'); $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_UserName"); session_register("MM_UserID"); session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> etc etc etc. If I want to now carry that username cookie over to the next page, do I also need to put in a set cookie command? Many thanks J Quote Link to comment https://forums.phpfreaks.com/topic/2901-code-check/ Share on other sites More sharing options...
binime Posted November 26, 2005 Share Posted November 26, 2005 session_start should often go straight after the opening php tags <?php session_start(); [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]If I want to now carry that username cookie over to the next page, do I also need to put in a set cookie command? in your next page if(isset($_COOKIE['UserName'])) { echo "welcome back ". $_COOKIE['UserName']; } else { echo "No user cookie found"; } Quote Link to comment https://forums.phpfreaks.com/topic/2901-code-check/#findComment-9878 Share on other sites More sharing options...
sgiandhu Posted December 13, 2005 Author Share Posted December 13, 2005 [!--quoteo(post=322188:date=Nov 26 2005, 02:19 AM:name=binime)--][div class=\'quotetop\']QUOTE(binime @ Nov 26 2005, 02:19 AM) 322188[/snapback][/div][div class=\'quotemain\'][!--quotec--] session_start should often go straight after the opening php tags <?php session_start(); in your next page if(isset($_COOKIE['UserName'])) { echo "welcome back ". $_COOKIE['UserName']; } else { echo "No user cookie found"; } Thanks - working properly now! Cheers, Joss Quote Link to comment https://forums.phpfreaks.com/topic/2901-code-check/#findComment-10172 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.