"74.124.195.113") ini_set("session.cookie_domain",".speaktomecatalog.com");
session_start() ;
# set the refer data in a cookie if we are from an external domain
$refererDomain=explode("/",$HTTP_REFERER);
$refererDomain=$refererDomain[2];
$ref['domain']=$refererDomain;
$ref['request']=$REQUEST_URI;
$ref['fromUri']=$HTTP_REFERER;
if ( $refererDomain=="speaktomecatalog.com"
or $refererDomain=="www.speaktomecatalog.com"
or $refererDomain=="74.124.195.113"
or $refererDomain=="dev.speaktomecatalog.com"){}
else { if ($HTTP_HOST=="74.124.195.113") setcookie("Referer", serialize($ref), 2147483647 , "/");
else setcookie("Referer",serialize($ref), 2147483647 , "/", ".speaktomecatalog.com");}
# calculate which page you came from
$fromPage= explode("/",getenv("HTTP_REFERER"));
$fromPage =$fromPage[3];
if ($fromPage == "getCatalog.html"){
# form posts to variables
$email = $_POST['email'];
$first = $_POST['first'];
$last = $_POST['last'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$zip = $_POST['zip'];
$city = $_POST['city'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$province = $_POST['province'];
$country = $_POST['country'];
$media = $_POST['media'];
# from variables to session
$_SESSION['email'] = $email;
$_SESSION['first'] = $first;
$_SESSION['last'] = $last;
$_SESSION['address'] = $address;
$_SESSION['address2'] = $address2;
$_SESSION['zip'] = $zip;
$_SESSION['city'] = $city;
$_SESSION['state'] = $state;
$_SESSION['phone'] = $phone;
$_SESSION['province'] = $province;
$_SESSION['country'] = $country;
$_SESSION['media']=$media;
# validate the data
$errors="";
if ($media=="email") {
# ----email: must be present and valid -----
if (empty($email)) {
$errors .= "
email is required when requesting email catalog
";}
if (!empty($email) AND !validate_email($email)){
$errors .= "invalid email
";}
} else {
# ----name: must have something in first or last
if (strlen(trim($first.$last))<4){
$errors .= "incomplete name
";}
# ----address: must be present
if (strlen(trim($address))<4){
$errors .= "incomplete address
";}
# ----state: us must have state
if ($state == "ZZ" ){
$errors .= "please choose a usa state
";}
# ----state: must have a zip code
if (empty($zip) ){
$errors .= "invalid zip code
";}
# ----city: must have city for usa
if (empty($city) ){
$errors .= "incomplete city
";}
}
} else {
# session to to variables and form
$email = $_SESSION['email'];
$first = $_SESSION['first'];
$last = $_SESSION['last'];
$address = $_SESSION['address'];
$address2 = $_SESSION['address2'];
$zip = $_SESSION['zip'];
$city = $_SESSION['city'];
$state = $_SESSION['state'];
$phone = $_SESSION['phone'];
$province = $_SESSION['province'];
$country = $_SESSION['country'];
$media= $_SESSION['media'];
}
if ( empty($errors) AND $fromPage=="getCatalog.html") {
# OK DATA IS VALID, WRITE THE RECORD
if ($HTTP_HOST=="dev.speaktomecatalog.com") $fp = fopen("/home/speakt5/orders/dev.wwwmail.tab", "a");
else $fp = fopen("/home/speakt5/orders/wwwmail.tab", "a");
$req = "www $media $first $last $address $address2 $city $state $zip $email \r\n";
fwrite($fp, $req);
fclose($fp);
# SAY THANK YOU
$response="We have your request for catalog. Please allow 3 to 4 weeks for your catalog to arrive.";
header("location: do.php?action=thanks&response=$response");
exit;
}
function validate_email($email)
{
// thanks http://www.developer.com/lang/php/article.php/10941_3290141_2
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
# function to persist the selected pulldown lists
function ck($this,$field){
if ($this == $field){
return "SELECTED";}
else { return "";}
}
?>
SpeakToMeCatalog: Request A Free Catalog