asked on
<?php
// required functions
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'post',
'content' => $data
)
);
if ($optional_headers!== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
// emulate form submissions to leads 360 and intellisource
$url = "http://www.intellisource.co.za/999_andycabenquiries.php"; // intellisource request
$data = "name=".$_POST["name"]. // First Name
"&surname=".$_POST["surname"]. // Last Name
"&email=".$_POST["email"]. // Email
"&textfield32=".$_POST["textfield32"]. // Phone
"&cellphone=".$_POST["cellphone"]. // Cellphone
"&message=".$_POST["message"]; // Message
$ret = do_post_request($url,$data); // post intellisource request id
echo $ret; // print intellisource return value
$url = "https://secure.leads360.com/Import.aspx?Provider=Vertical". // leads 360 url
"Masters-Other&Client=LMX-9014&CampaignId=7075";
$data = "Ref Id= ". // Lead Provider ID
"&First Name=".$_POST["name"]. // First Name
"&Last Name=".$_POST["surname"]. // Last Name
"&Email=".$_POST["email"]. // Email
"&Home Phone=".$_POST["textfield32"]. // Home Phone
"&Work Phone=".$_POST["textfield32"]. // Work Phone
"&Mobile Phone=".$_POST["cellphone"]. // Mobile Phone
"&Message=".$_POST["message"]. // Message
"&AndyCab ID=".$ret; // add andycab id retrieved from intellisource
$ret = do_post_request($url,$data); // post leads 360 request
echo $ret; // print leads 360 return value
?>
now with the current configuration of server A, this code works posting to both server A and server B when testing from server A - but with the unknown configuration of server C, i need to figure out why i am getting the following exception and if there is a way to get any more details when running. the response on server C:<br />
<b>Fatal error</b>: Uncaught exception 'Exception' with message 'Problem with http://www.intellisource.co.za/999_andycabenquiries.php, ' in /usr/www/users/andyca/intellisourceleads360.php:15
Stack trace:
#0 /usr/www/users/andyca/intellisourceleads360.php(35): do_post_request('http://www.inte...', 'name=Pierre&sur...')
#1 /usr/www/users/andyca/form.php(5): include_once('/usr/www/users/...')
#2 {main}
thrown in <b>/usr/www/users/andyca/intellisourceleads360.php</b> on line <b>15</b><br />
the A server is www.intellisource.co.za which is on an Apache 2.2.19 machine.<?php
$GLOBALS["sql"] = array();
$conn = mysql_connect("localhost", "dwtphovu_f3rr37y", "JapieMySkapie101");
if (!$conn) {
$err = "ERROR #".mysql_errno()."Could not connect: ".mysql_error()." in ".$doc." on Line ".$line;
array_push($GLOBALS["sql"],$err);
}
mysql_select_db("dwtphovu_8347379386_prod", $conn);
function mysql_query_errors($sql, $conn, $doc, $line, $expret = false) {
$line--;
$err = "";
$result = mysql_query($sql);
if (mysql_errno() > 0) {
$err = "ERROR #".mysql_errno().": ".mysql_error()." in ".$doc." on Line ".$line;
} elseif ($expret) {
if (is_null($result)) {
$err = "NOTICE #0504: A null value was returned by the query defined in ".$doc." on line ".$line--;
} elseif ($result === false) {
$err = "NOTICE #0502: A false value was returned by the query defined in ".$doc." on line ".$line--;
} elseif ($result === true) {
$err = "NOTICE #0501: A true value was returned by the query defined in ".$doc." on line ".$line--;
} elseif (mysql_num_rows($result) < 1) {
$err = "NOTICE #0500: An empty result set was returned by the query defined in ".$doc." on line ".$line--;
}
array_push($GLOBALS["sql"],$sql."\n",$err."\n");
}
return $result;
}
/* **************************************************************************************************
function str_in_array($haystack, $needle, $sw = 1) {
foreach ($haystack as $value[0] => $value[1]) {
if (stristr($value[$sw],$needle)!==FALSE) {
return true;
}
}
return false;
}
// get table fields to compare with form
$existing = array();
$tsql = "SHOW COLUMNS FROM dwtphovu_8347379386_prod.999_andycabenquiries;";
$result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
if ($row["Field"] != "bigint_EnquiryID") {
array_push($existing,$row["Field"]);
}
}
}
echo "\$existing = ".print_r($existing,true)."<br>";
// alter table to add new fields if found
$tocreate = array();
foreach ($_POST as $key=>$value) {
if ($key != "Reset" &&
$key != "Submit2" &&
!str_in_array($existing,$key)) {
array_push($tocreate,ucfirst($key));
}
}
echo "\$tocreate = ".print_r($tocreate,true)."<br>";
foreach ($tocreate as $key=>$value) {
$asql = "ALTER TABLE
dwtphovu_8347379386_prod.999_andycabenquiries
ADD
`text_Enquiry".$value."`
TEXT CHARACTER SET utf8
COLLATE utf8_unicode_ci
NULL
DEFAULT NULL
COMMENT 'Enquiry ".$value."',
ADD FULLTEXT 'FULLTEXT' (
`text_Enquiry".$value."`
)";
$result = mysql_query_errors($asql, $conn, __FILE__, __LINE__);
}
echo print_r($GLOBALS["sql"],true);
************************************************************************************************** */
// insert new record
$tsql = "INSERT INTO
dwtphovu_8347379386_prod.999_andycabenquiries
(
text_EnquiryName,
text_EnquirySurname,
text_EnquiryEmail,
text_EnquiryPhone,
text_EnquiryCellPhone,
text_EnquiryMessage
) VALUES (
\"".mysql_real_escape_string($_POST["name"])."\",
\"".mysql_real_escape_string($_POST["surname"])."\",
\"".mysql_real_escape_string($_POST["email"])."\",
\"".mysql_real_escape_string($_POST["textfield32"])."\",
\"".mysql_real_escape_string($_POST["cellphone"])."\",
\"".mysql_real_escape_string($_POST["message"])."\"
);";
$result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);
echo (count($GLOBALS["sql"]))?implode("\n",$GLOBALS["sql"]):mysql_insert_id($conn);
document B is a third party lead manager.