#native_company# #native_desc#
#native_cta#

Cookies – Remember Your Info?

By Panos A
on December 12, 2002

Version: 1.1

Type: Full Script

Category: Other

License: GNU General Public License

Description: The user is checking out. They fill in the form with their name, address, email, state, zip etc.
They choose “Yes” to the option “Remember your info?” So, you take the values from the
text boxes and store them in a cookie, set to expire in one year. Next time they visit, you
pull the values from the cookie and automatically fill out the form fields

1.1 Fixed a huge bug.
********************************************************************
The user is checking out. They fill in the form with their name, address, email, state, zip etc.
They choose "Yes" to the option "Remember your info?" So, you take the values from the 
text boxes and store them in a cookie, set to expire in one year. Next time they visit, you 
pull the values from the cookie and automatically fill out the form fields. Being a newbie, it
took me 2 good days to figure out how to do this. I could not, for the life of me, find exactly
the code that I needed. So when I finally figured it out, I thought I'd put it out there there for
whoever needs it.
Install:
You should have 3 files:
1.globl.php
2.userInfo.php
3.action.php
Just copy or upload them and point your browser to userInfo.php.
That's it.
********************************************************************

************************ userInfo.php ******************************
<?
require("globl.php");
getTheInfo($HTTP_COOKIE_VARS["mycookie"],0);
mHeader("Company","Give me your info please");
echo "<form action="action.php" method="post"><table border="0"><tr><td>";
echo "Name:<br><input type="text" name="Name" value="$v[0]" size="40"><p>";
echo "Address1:<br><input type="text" name="Address1" value="$v[1]" size="40"><br>";
echo "Address2:<br><input type="text" name="Address2" value="$v[2]" size="40"><p>";
echo "City, State, Zip:<br><input type="text" name="City" value="$v[3]" size="25">";
echo "&nbsp;&nbsp;<input type="text" name="State" value="$v[4]" size="2" MAXLENGTH="2">";
echo "&nbsp;&nbsp;<input type="text" name="Zip" value="$v[5]" size="7" maxlength="12"><p>";
echo "Email:<br><input type="text" name="Email" value="$v[6]" size="40"><p>";
echo "Day Phone:<br><input type="text" name="DayPhone" value="$v[7]" size="40"><p>";
echo "Evening Phone:<br><input type="text" name="EvePhone" value="$v[8]" size="40"><p>";
echo "Remember your info next time you visit?<br>";
echo "<INPUT TYPE="radio"  NAME="remember"  VALUE="Yes">Yes &nbsp;";
echo "<INPUT TYPE="radio"  NAME="remember"  VALUE="No" checked>No";
echo "<P><input type="submit" value="Submit"></form>";
mFooter("userInfo.php");
?>
*******************************************************************

********************* globl.php ***********************************
<?
function setTheCookie($Name,$Address1,$Address2,$City,$State,$Zip,$Email,$DayPhone,$EvePhone) {
	if ($Name == ""){
		$Name = " ";
	}
	if ($Address1 == ""){
		$Address1 = " ";
	}
	if ($Address2 == ""){
		$Address2 = " ";
	}
	if ($City == ""){
		$City = " ";
	}
	if ($State == ""){
		$State = " ";
	}
	if ($Zip == ""){
		$Zip = " ";
	}
	if ($Email == ""){
		$Email = " ";
	}
	if ($DayPhone == ""){
		$DayPhone = " ";
	}
	if ($EvePhone == ""){
		$EvePhone = " ";
	}
setcookie ("mycookie[Name]", $Name,time()+15552000); //Set to expire in 1 year
setcookie ("mycookie[Address1]", $Address1,time()+15552000);
setcookie ("mycookie[Address2]", $Address2,time()+15552000);
setcookie ("mycookie[City]", $City,time()+15552000);
setcookie ("mycookie[State]", $State,time()+15552000);
setcookie ("mycookie[Zip]", $Zip,time()+15552000);
setcookie ("mycookie[Email]", $Email,time()+15552000);
setcookie ("mycookie[DayPhone]", $DayPhone,time()+15552000);
setcookie ("mycookie[EvePhone]", $EvePhone,time()+15552000);
}

function getTheInfo($cookiename,$count) {
	global $v;
	if (isset ($cookiename)) {
    while (list ($name, $value) = each ($cookiename)) {
        $v[$count] = $value;
        $count++;
    }
  }
}

function deleteTheCookie() {
setcookie ("mycookie[Name]", "",time() - 3600); //Set to expire 1 our ago
setcookie ("mycookie[Address1]", "",time() - 3600);
setcookie ("mycookie[Address2]", "",time() - 3600);
setcookie ("mycookie[City]", "",time() - 3600);
setcookie ("mycookie[State]", "",time() - 3600);
setcookie ("mycookie[Zip]", "",time() - 3600);
setcookie ("mycookie[Email]", "",time() - 3600);
setcookie ("mycookie[DayPhone]", "",time() - 3600);
setcookie ("mycookie[EvePhone]", "",time() - 3600);

}


function mHeader($Company,$title) {
echo "<HTML><HEAD><TITLE>$Company - $title</TITLE></HEAD><BODY BGCOLOR="#FFFFFF" text="#968372" link="#000099" vlink="#CC0000" alink="#FF00FF">";
}
function mFooter($home) {
echo "<center><br><br><hr width="70%"><br>";
echo "<a href="$home">Home</a>";
}
?>
***************************************************************************

********************************* action.php ******************************
<?
require("globl.php");
if ($remember == "Yes") {
setTheCookie($Name,$Address1,$Address2,$City,$State,$Zip,$Email,$DayPhone,$EvePhone);
}
else {
	deleteTheCookie();
}
mHeader("Company Name Here","Thank You");
echo"Thank you ...";
mFooter("userInfo.php");
?>
*****************************************************************************