我试图在我的php文件register.php
中插入图片像素。 img
标记充当跟踪代码,每次用户注册时,跟踪代码都会将数据发送到网站。现在它发出警报Unexpected token JSON
并且注册无效。有没有人可以帮助我,我只需要正确地设置跟踪代码,但我不知道如何。
function post_register($field) {
$captcha;
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
$secretKey = "xxxx";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
global $wpdb;
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$business_number = $_POST['business_number'];
$email = $_POST['email'];
$password = $_POST['register_password'];
$password_confirmation = $_POST['password_confirmation'];
$gbv_website = $_POST['gbv_website'];
$hear_about_us = $_POST['hear_about_us'];
$hasError = false;
$user_id = '';
/*$howto = $_POST['howto'];
$callTransfer = $_POST['callTransfer'];*/
if(trim($first_name) === '') {
$error = 'Please enter your first name.';
$hasError = true;
}elseif(trim($last_name) === '') {
$error = 'Please enter your last name.';
$hasError = true;
}elseif(trim($business_number) === '') {
$error = 'Please enter your business number.';
$hasError = true;
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL) ) {
$error = 'Please enter a valid email.';
$hasError = true;
}elseif($password === '') {
$error = 'Please enter your password';
$hasError = true;
}elseif($password !== $password_confirmation){
$error = 'Password verification did not matched!';
$hasError = true;
}elseif(trim($gbv_website) === '') {
$error = 'Please enter your Website.';
$hasError = true;
}elseif(trim($hear_about_us) === '') {
$error = 'Please select one.';
$hasError = true;
}elseif(email_exists($email)){
$error = 'Email address already exists';
$hasError = true;
}
/*elseif(trim($howto) === ''){
$error = 'Please select if Message Only or Call Screening & Transfer';
$hasError = true;
}*/
else{
// create user
$user_id = wp_insert_user(['user_login' => $email, 'user_pass' => $password, 'user_email' => $email, 'first_name' => $first_name, 'last_name' => $last_name]);
// echo '<img src="https://shareasale.com/sale.cfm?amount=90.00&tracking=1&transtype=sale&merchantID=49748" width="1" height="1">';
if(is_wp_error($user_id)){
$error = $user_id->get_error_message();
$hasError = true;
}
}
if ($user_id > 0){
//create user profile
$profile_inserted = post_create_profile($user_id, $first_name, $last_name, $hear_about_us, $business_number, $email, $howto, $callTransfer);
if(!$profile_inserted){
wp_delete_user($user_id);
$error = 'System encountered problem while creating your profile, please try again';
$hasError = true;
}else{
//create user answer
$answer_inserted = post_create_answer($user_id, $gbv_website);
if(!$answer_inserted){
wp_delete_user($user_id);
$error = 'System encountered problem while creating your answer, please try again';
$hasError = true;
}
}
}
if($hasError) wp_redirect('/sign-up?error=' . urlencode($error));
return $user_id;
}
}
/*
END OF REGISTRATION
-------------------
CREATE PROFILE
*/
function post_create_profile($user_id, $first_name, $last_name, $hear_about_us, $business_number, $email, $howTo, $callTransfer){
global $wpdb;
return $wpdb->insert(
$wpdb->prefix .'user_profile',
[
'user_id' => $user_id,
'full_name' => $first_name .' '. $last_name,
'hear_about_us' => $hear_about_us,
'business_number' => serialize(['business_number' => $business_number]),
'email_id' => $email,
'ip_address' => $_SERVER['REMOTE_ADDR'],
'status' => 6, //new register
'add_date' => date('Y-m-d, H:i:s'),
'how_to' => $howTo,
'call_transfer' => $callTransfer,
]);
}
/*
END CREATE PROFILE
------------------
CREATE ANSWER
*/
function post_create_answer($user_id, $gbv_website){
global $wpdb;
return $wpdb->insert($wpdb->prefix .'user_answer', ['user_id' => $user_id, 'website' => $gbv_website, 'add_date' => date('Y-m-d, H:i:s')]);
}
/*
END CREATE ANSWER
------------------
SUBSCRIPTION
*/
function post_subscribe($provisioning){
global $wpdb;
$user = get_userdata($provisioning->user_id);
$subscription_id = elegant_id($provisioning->user_id);
$phone_num = unserialize($provisioning->phone_num);
$address = unserialize($provisioning->address);
try{
$result = ChargeBee_Subscription::create(array(
'id' => $subscription_id,
'planId' => 'popular-plan',
'customer' => [
'id' => $subscription_id,
'email' => $user->user_email,
'firstName' => $user->first_name,
'lastName' => $user->last_name,
'company' => $provisioning->company_name,
'phone' => $phone_num['phone_number']
],
'billingAddress' => [
'firstName' => $user->first_name,
'lastName' => $user->last_name,
'email' => $provisioning->email_id,
'company' => $provisioning->company_name,
'phone' => $phone_num['phone_number'],
'line1' => $address['address1'],
'line2' => $address['address2'],
'city' => $provisioning->city,
'state' => $provisioning->state,
// 'zip' => $provisioning->zip,
'country' => 'US',
]
));
$wpdb->update(
$wpdb->prefix .'user_answer',
[
'chargebee_customer_id' => $subscription_id,
'chargebee_subscription_id' => $subscription_id,
],
['id' => $provisioning->user_answer_id]);
$wpdb->update($wpdb->prefix .'user_profile', ['status' => 2], ['id' => $provisioning->user_profile_id]);
return ['result' => 'success', 'result' => $result->subscription()];
}catch(Exception $e){
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
add_action( 'wp_ajax_nopriv_check_user_email', 'check_user_email_callback' );
function check_user_email_callback() {
global $wpdb; // this is how you get access to the database
if(email_exists($_POST['email'])){
echo json_encode('Email address already used.');
}
else{
echo json_encode('true');
}
die();
}
echo '<img src="https://shareasale.com/sale.cfm?amount=59.00&tracking=12345&transtype=sale&merchantID=xxxxx" width="1" height="1">';