I have some working cURL scripts but have been relying on the remote server for SS validation. I want to add some validation to our cURL scripts so that if they aren't filled out correctly the request won't get sent. I have client side JS validation, but want to duplicate with SS validation. Here is an example of my cURL script:
<?php
$url = 'https://remoteserver.com/POST.svc/Foo';
$Field1 = $_POST["Field1"];
//other input data
$fields = array(
'Field1'=>urlencode($Field1),
//other input data
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'& ');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
Can I just create an if/else statement like:
<?php
if(empty($_POST['Field1']))) {
echo "Error";
die();
} else {
$url = 'https://remoteserver.com/POST.svc/Foo';
$Field1 = $_POST["Field1"];
//other input data
$fields = array(
'Field1'=>urlencode($Field1),
//other input data
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'& ');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
}
I have ajax stuff that is displayed if the return is "Error". This can't be that easy, is it?
thx