I have a user log in using SESSION variables. All I want to do is add a $_COOKIE (If user checks box in form) using the values of my SESSION..
Code: Select all
<?php
session_start();
if(isset($_POST['radio_button']))
{
//This outputs
$u = rand();
setcookie("cook",$u,time() +3600);
//This DOESN'T output...and I can't figure out why
$user = $_SESSION['MM_Username'];
setcookie("user",$user, time() +3600);
}
?>
<html>
$a = $_SESSION['test'];
echo $a;
But when I try to use it in setcookie() it doesn't, i.e. example above. I've also tried $_POST to no avail.
$user = $_POST['MM_Username'];
setcookie("user",$user, time() +3600);
Here is all of it
Code: Select all
<?php require_once('Connections/login.php'); ?>
<?php
session_start();
if(isset($_POST['radio_button']))
{
$u = rand();
setcookie("cook",$u,time() +3600);
$user = $_SESSION['MM_Username'];
setcookie("user",$user, time() +3600);
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?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['name'])) {
$loginUsername=$_POST['name'];
$password=$_POST['pass'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "kepp_login_with_cookie.php";
$MM_redirectLoginFailed = "kepp_login_with_cookie.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_login, $login);
$LoginRS__query=sprintf("SELECT user_name, user_pass FROM login WHERE user_name=%s AND user_pass=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $login) 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 );
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="400" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>name</td>
<td>
<label>
<input type="text" name="name" id="name" />
</label>
</td>
<td> </td>
</tr>
<tr>
<td>pass</td>
<td>
<label>
<input type="password" name="pass" id="pass" />
</label>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
<label>
<input type="radio" name="check_box" id="stay" value="stay" />
</label></td>
<td> </td>
</tr>
</table> </form>
<p>You are logged in as
<?php
if(!isset($_SESSION['MM_Username']))
{
echo "guest";
}
else
{
echo $_SESSION['MM_Username'];
}
?>
<br/>
</p>
<p> </p>
<p><a href="clear_session.php">sign out</a></p>
</body>
</html>