Posted: Wed Mar 28, 2007 8:43 am
At some point $_POST['marketsource'] was converted to a string directly from an array, thus resulting in the string "Array." Trace the variable backward to find the culprit.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
/** 1 **/
session_start();
/** 2 **/
//See if evil magic_quotes is enabled, and fix problems if it is
$quotes_on = (get_magic_quotes_gpc() || get_magic_quotes_runtime());
if ($quotes_on)
{
foreach ($_POST as $key => $value)
{
$_POST[$key] = stripslashes($value);
}
}
/** 3 **/
$_SESSION["post"] = $_POST;
/** 4 **/
//Load in the required Swift files
require_once "classes/Swift.php";
require_once "classes/Swift/Connection/SMTP.php";
/** 5 **/
//Create an empty array where we can catch any fields which were not filled in
$fields_not_set = array();
//FOR EACH REQUIRED FIELD
//Check if all POST data was sent, redirect with an error if not
if (empty($_POST["Name"])) $fields_not_set[] = "Name";
if (empty($_POST["Email"])) $fields_not_set[] = "Email";
//if (empty($_POST["subject"])) $fields_not_set[] = "subject";
//if (empty($_POST["comments"])) $fields_not_set[] = "comments";
//If $fields_not_set contains any values, then something wasn't filled in. Time to redirect.
if (!empty($fields_not_set))
{
//Read further down to see how we'll modify form.php to handle the error
header("Location: contact_us.php?error=incomplete&fields=" . implode(",", $fields_not_set));
exit();
}
//Copy the POST data to standard globals
$name = $_POST["Name"];
$email = $_POST["Email"];
$address = $_POST["Addy"];
$citystatezip = $_POST["CSZ"];
$entitytype = $_POST["entitytype"];
//var_dump($_POST["marketsource"]);
$marketsource = implode(", ", $_POST['marketsource']);Code: Select all
if ($quotes_on)
{
foreach ($_POST as $key => $value)
{
$_POST[$key] = stripslashes($value);
}
}Frankly, I'm still not sure. I did get it beat into my brain that an array is not a string and that stripslashes is a function written for strings. I could not discover what actually happens when you give stripslashes an array, however. I just learned it "don't work."d11wtq wrote:What's $_POST["marketsource"]? An array. What happens when you pass that array to stripslashes() ?
Code: Select all
/** 2 **/
//See if evil magic_quotes is enabled, and fix problems if it is
$quotes_on = (get_magic_quotes_gpc() || get_magic_quotes_runtime());
if ($quotes_on)
{
foreach ($_POST as $key => $value)
{
// $_POST[$key] = stripslashes($value);
// if (is_array($_POST)) $_POST[$key] = stripslashes(&$value);
// else $_POST[$key] = stripslashes($value);
// if (is_array($_POST)) array_map($_POST[$key] = stripslashes(&$value));
// else $_POST[$key] = stripslashes($value);
// if (is_array($value)) array_walk($_POST[$key] = stripslashes(&$value));
// else $value = stripslashes($value);
if (is_array($value))
{
foreach ($value as $index => $value)
{
$value[$index] = stripslashes($value);
}
}
else $_POST[$key] = stripslashes($value);
}
}Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache/hosts/domain/pub/parseandsend.php:6) in /usr/local/apache/hosts/domain/pub/parseandsend.php on line 178Code: Select all
{
unset($_SESSION["post"]); //It worked, we have no reason to keep this data
$swift->close();
header("Location: contact_us_thanks.php"); /** 13 **/ //THIS IS LINE 178
exit();
}
else
{
$swift->close();
header("Location: contact_us.php?error=runtime_error"); /** 13 **/
exit();
}I wanted to try this out but have problem in that there seems no file "lib/classes/Swift/Connection/SMTP.php" in my recent installation of Swift-5.1.0 ... would you have any information of changes since the time you wrote the above script and which file in the new Swift version needs to be entered here ?/** 4 **/
//Load in the required Swift files
require_once "classes/Swift.php";
require_once "classes/Swift/Connection/SMTP.php";