Changes

Scenario - bxp as a secure Website Data Store

3,322 bytes added, 09:08, 20 January 2015
no edit summary
= External Setup =
 
 
So now we want to be able to write some data into the form and read some data from the form.
== Write some data ==
 
 
When writing data there are two primary operations. Create a record and Update a record. bxp uses a simple system, IF the Id is set, it is an update. If the ID is not set, then a new record will be created.
 
 
So to write to a form, we use the material as per 7.4.4 Website – Data Logging
 
<syntaxhighlight lang="php">
//=========================================================
//Data Setup
//=========================================================
$url = 'https://ww3.allnone.ie/client/client_demo/cti/userCTI_GenericEntry.asp';
//set the extrac POST variables required
$fields = array(
'user_id' => urlencode('testing'),
'user_key' => urlencode('testing'),
'system' => urlencode('formlogging'),
'campaignid' => urlencode('56')
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
//extract data from the post
foreach($_POST as $key => $value) {
$fields_string .= $key.'='.urlencode($value).'&';
}
rtrim($fields_string,'&');
//=========================================================
//Process Data
//=========================================================
//open connection and set the url, number of POST vars, POST data, execute post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch);
curl_close($ch);
//=========================================================
//Result management
//=========================================================
if (strpos($result,'record>-1<')) {
$strMessage = 'Sorry but that is an incorrect username or password for logging this record.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-2<')) {
$strMessage = 'Sorry but that is an incorrect IP address to log from that account.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-3<')) {
$strMessage = 'Sorry but that form is not available to the public for storing data in.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-4<')) {
$strMessage = 'Sorry but that form has not been built properly.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-5<')) {
$strMessage = 'Sorry but that form is not active.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-6<')) {
$strMessage = 'Sorry but that user cannot log data in that form.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>-7<')) {
$strMessage = 'Sorry but no public outcome has been set to process that record.<br />Please contact the site Administrator';
} elseif (strpos($result,'record>0<')) {
$strMessage = 'Sorry but no Id was returned.<br />Please contact the site Administrator';
} else {
$result = str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "", $result);
$result = str_replace("\n", "", $result);
$result = str_replace("<record>", "", $result);
$result = str_replace("</record>", "", $result);
$strMessage = "The record has been logged with an Id of ".$result.".";
}
echo $strMessage;
</syntaxhighlight>
 
7,528
edits