ERRORS WITH MY CONTACT.PHP - TRYING TO GET SIGNATURES TO SHOW UP

27 views
Skip to first unread message

Bradley Ambrose

unread,
Jun 25, 2015, 3:22:53 PM6/25/15
to change-...@googlegroups.com

I copied the code from gihub but it's not working. Any suggestions would be awesome!

Here is what I have...

<?php 

/* ==========================  Define variables ========================== */

//Check e-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}

/* ==========================  Define variables ========================== */

error_log('fuck this bs.');
// var_dump($_POST);

//Get post data
if( isset($_POST['first_name']) and isset($_POST['last_name']) and isset($_POST['mail']) and isset($_POST['comment']) ){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$mail = $_POST['mail'];
$website  = $_POST['website'];
$comment = $_POST['comment'];

$name = $first_name . ' ' . $last_name;
error_log($name);

if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Please enter your name."));
exit();
} else if($mail == '' or check_email($mail) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail."));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your message."));
exit();
} else {
//Sign petition
// cd to /Users/bambrose87/Desktop/sites/themeforest-11606555-unika-responsive-material-design-onepage-html-template/SPELL_Petitions_Rule
// php -S localhost:8000
error_log("Start here and make it work.");


$api_key = '1f6e41aada6cd7de9e0cfa696aab23ecce67a7aee4540b19eb99a9b06c4857b1';
$secret = '4bbaa9cae9d27b607a382b5913fcf420281bb2cea72d1616296db5588afb28ef';
$petition_auth_key = '3561135';

$base_url = "https://api.change.org";
$endpoint = "/v1/petitions/$petition_id/signatures";
$url = $base_url . $endpoint;

$parameters = array();
$parameters['api_key'] = $api_key;

$parameters['source'] = 'test.com';
$parameters['email'] = 'per...@example.com';
$parameters['first_name'] = 'John';
$parameters['last_name'] = 'Doe';
$parameters['address'] = '1 Market St';
$parameters['city'] = 'Philadelphia';
$parameters['state_province'] = 'PA';
$parameters['postal_code'] = '19144';
$parameters['country_code'] = 'US';


$parameters['timestamp'] = gmdate("Y-m-d\TH:i:s\Z"); // ISO-8601-formtted timestamp at UTC
$parameters['endpoint'] = $endpoint;

$query_string_with_secret_and_auth_key = http_build_query($parameters) . $secret . $petition_auth_key;

$parameters['rsig'] = hash('sha256', $query_string_with_secret_and_auth_key);


$data = http_build_query($parameters);

error_log("here 1");

$curl_session = curl_init();
curl_setopt_array($curl_session, array(
   CURLOPT_POST => 1,
   CURLOPT_URL => $url,
   CURLOPT_POSTFIELDS => $data
));

$result = curl_exec($curl_session);

error_log("here 2");
error_log($result);
echo $result;


}
} else {
echo json_encode(array('info' => 'error', 'msg' => 'Please fill out the required fields.'));
}


 ?>

Reply all
Reply to author
Forward
0 new messages