session_destroy()最近停止了工作,现在活动会话没有被破坏。我已尝试过SE上提到的所有解决方案,但它们无法正常工作。下面是我正在使用的代码。
session_start(); # NOTE THE SESSION START
$_SESSION = array();
session_unset();
session_destroy();
header('Location: thankyou');
exit();
整个脚本:
<?php
//session_start();
$to = 'equote@domain.com';
$products = $_POST['product_id'];
$subject = "Request Quote";
$errors = array();
$i = 0;
if(!isset($_POST['name']) || $_POST['name'] == ''){
$errors[$i] = 'Please enter your Name';
$i++;
}
if(!isset($_POST['company_name']) || $_POST['company_name'] == ''){
$errors[$i] = 'Please enter your Company Name';
$i++;
}
if(!isset($_POST['phone']) || $_POST['phone'] == ''){
$errors[$i] = 'Please enter your Phone Number';
$i++;
}
if(!isset($_POST['email']) || $_POST['email'] == ''){
$errors[$i] = 'Please enter your Email';
$i++;
}
/*if($_POST['email2'] != $_POST['email'] ){
$errors[$i] = 'Your Email does not match';
$i++;
}*/
if($i > 0){
$msg = serialize($errors);
$info = serialize ($_POST);
header('Location: /checkout/cart/?msg='.$msg.'&info='.$info);
exit;
}
$name = mysql_escape_string($_POST['name']);
$company_name = mysql_escape_string($_POST['company_name']);
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$contact_by = $_POST['contact_by'];
$sales_person = $_POST['sales_person'];
$items = '';
foreach($products as $product){
$items .= $product . ',';
}
//connect to the DB!!
mysql_connect('localhost','machiner_dbusr','d2eV3k98Zx76YgZ');
mysql_select_db('machiner_db');
$date = date('m-d-Y');
$sql = "INSERT INTO `quote` (`name`, `company_name`, `address`, `city`, `state`, `zip`, `country`, `phone`, `fax`, `email`, `contact_by`, `item_skus`, `date`) VALUES ('$name', '$company_name', '$address', '$city', '$state', '$zip', '$country', '$phone', '$fax', '$email', '$contact_by', '$items', '$date')";
mysql_query($sql);
$name = $_POST['name'];
$company_name = $_POST['company_name'];
$i = 0;
foreach($products as $product){
$entity_id = 0;
$product = str_replace(' ','',$product);
$sql = "SELECT `entity_id` FROM `catalog_product_entity` WHERE `sku` ='$product'";
$result = mysql_query($sql);
if($row = mysql_fetch_assoc($result)){
$entity_id = $row['entity_id'];
}
if($entity_id != 0){
$sql = "SELECT `value` FROM `catalog_product_entity_text` WHERE `entity_id` ='$entity_id' AND `attribute_id` ='58'";
$result = mysql_query($sql);
if($row = mysql_fetch_assoc($result)){
$product_name[$i] = $row['value'];
}
$sql = "SELECT `value` FROM `catalog_product_entity_varchar` WHERE `entity_id` ='$entity_id' AND `attribute_id` ='446'";
$result = mysql_query($sql);
if($row = mysql_fetch_assoc($result)){
$location[$i] = $row['value'];
}
} else{
$product_name[$i] = '';
}
$i++;
}
$message = '';
$message .= 'Company Name: '.$_POST['company_name']. "\n";
//$message .= 'Address: '.$_POST['address']. "\n";
//$message .= 'City: '.$_POST['city']. "\n";
//$message .= 'State: '.$_POST['state']. "\n";
//$message .= 'Zip Code: '.$_POST['zip']. "\n";
$message .= 'Country: '.$_POST['country']. "\n";
$message .= 'Name of Person: '.$_POST['name'] . "\n";
$message .= 'Phone: '.$_POST['phone']. "\n";
/*$message .= 'Fax: '.$_POST['fax']. "\n";*/
$message .= 'Email: '.$_POST['email']. "\n\r";
$message .= 'Comments: '.$_POST['comments']. "\n\r";
$message .= 'Inventory Items:'. "\n";
//$message .= '<table cellpadding="5" width="100%">'. "\n\r";
//$message .= '<thead>'. "\n\r";
//$message .= '</thead>'. "\n\r";
//$message .= '<tbody>'. "\n\r";
$i = 0;
foreach($products as $product){
$message .= 'Stock Number: '. $product. "\n";
$message .= 'Description: '. $product_name[$i]. "\n";
$message .= 'Location: '. $location[$i] . "\n\r";
//$message .= '<tr><td>'.$product.' </td><td>'.$product_name[$i].'</td><td>'.$location[$i].'</td>'.'</tr>'. "\n\r";
$i++;
}
//$message .= '</tbody>'. "\n\r";
//$message .= '</table>'. "<br />\n\r";
// To send HTML mail, the Content-type header must be set
//$headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers = 'From: '.$_POST['name'].' <'.$_POST['email'].'>' . "\r\n";
mail($to, $subject, $message, $headers);
session_start(); # NOTE THE SESSION START
$_SESSION = array();
session_unset();
session_destroy();
header('Location: thankyou');
exit();
?>
答案 0 :(得分:0)
我只是清楚$ _SESSION,它总是适用于我。
<?
session_start();
$_SESSION = array();
header("Location: index.php");
?>
然后你必须在你的脚本中使用$ _SESSION。