tomm098 Posted May 4, 2010 Share Posted May 4, 2010 Hey all. I currently have SESSION implemented in my site and would like it to set cookies when someone logs in. Does anyone know what to write in my validation PHP. Here is the code. <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['Username'])) { $loginUsername=$_POST['Username']; $password=$_POST['Password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "loginsuccesful.php"; $MM_redirectLoginFailed = "loginfailed.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_test, $test); $LoginRS__query=sprintf("SELECT Username, Password FROM Users WHERE Username=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> Link to comment https://forums.phpfreaks.com/topic/200637-how-do-i-set-cookies/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.