Skip to content

Instantly share code, notes, and snippets.

@dtbaker
Created October 6, 2014 05:20
Show Gist options
  • Save dtbaker/45948f58ee7a66619c13 to your computer and use it in GitHub Desktop.
Save dtbaker/45948f58ee7a66619c13 to your computer and use it in GitHub Desktop.
proxy PHP script for handling UCM customer signups
<?php
// upload this signup.php form to your website then change the UCM form action="" to this signup.php file (e.g. <form action="http://yourwebsite.com/signup.php"> )
// CHANGE THIS URL TO YOUR UCM SIGNUP URL
$url = "http://yourwebsite.com/ucm/ext.php?m=customer&h=public_signup";
$ch = curl_init($url);
// put your code here that does any local processing with form submit data
//print_r($_POST);
function flatten($array, $prefix = '', $depth = 0) {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + flatten($value, $prefix . ($depth > 0 ? '['.$key .']' : $key), $depth+1);
}
else {
if($depth>0){
$result[$prefix . '[' . $key . ']'] = $value;
}else{
$result[$prefix . $key] = $value;
}
}
}
return $result;
}
$data = flatten($_POST);
if(isset($_FILES) && is_array($_FILES)) {
// todo. php5.5 use curlfile class
foreach ( $_FILES as $file_key => $file_data ) {
if ( isset( $file_data['name'] ) ) {
$is_array = false;
if ( ! is_array( $file_data['name'] ) ) {
$file_data['name'] = array( $file_data['name'] );
$file_data['type'] = array( $file_data['type'] );
$file_data['tmp_name'] = array( $file_data['tmp_name'] );
$file_data['error'] = array( $file_data['error'] );
$file_data['size'] = array( $file_data['size'] );
} else {
// already an array of files.
//$file_key = $file_key . '[]';
$is_array = true;
}
foreach ( $file_data['tmp_name'] as $key => $tmp_name ) {
if ( is_uploaded_file( $tmp_name ) ) {
//$post_string .= '&' . urlencode($file_key) .'=@' . $tmp_name . ';filename=' . urlencode($file_data['name'][ $key ]).';type='.urlencode($file_data['type'][$key]);
$cfile = curl_file_create($tmp_name, $file_data['type'][$key], $file_data['name'][ $key ]);
//$cfile = '@' . $tmp_name . ';filename=' . urlencode($file_data['name'][ $key ]).';type='.urlencode($file_data['type'][$key]);
if($is_array){
if(!isset($data[$file_key])){
$data[$file_key] = array();
}
$data[$file_key][] = $cfile;
}else{
$data[$file_key] = $cfile;
}
}
}
}
}
}
// this is the URL of the OTHER website that will receive a copy of the form submission data
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
//echo $response;
if(strpos($response,"Failed")){
echo "The signup failed. Display your custom message here";
}else{
echo "The signup worked. Display your custom message here or redirect here";
//header("Location: http://google.com");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment