I have a JSON API Add-on.
There is a query for getting the result stored in the database but it gives a different response in the different systems.
I already cleared the browser cookies and cache but nothing happens. It stores device id again and again even it already store
My function is as follow:
public function store_device_id()
{
global $wpdb;
$device_id = $_REQUEST['device_id'];
$device_type = $_REQUEST['device_type'];
$table_name = $wpdb->prefix . 'ws_details';
if(!empty($device_id) && !empty($device_type)) :
$check = $wpdb->get_row( "SELECT * FROM $table_name WHERE device_id like '%".$device_id."%'" );
if($check == '')
{
$result = $wpdb->insert( $table_name,array(
'time' => current_time( 'mysql' ),
'device_id' => $device_id,
'device_type' => $device_type ),
array( '%s', '%s', '%s'));
if ($result)
{
$res = 'Device id saved.';
} else {
$res = 'Device id did not save.';
}
}
else{
$res = 'Device already register.';
}
else :
$res = 'Please enter device id & device type.';
endif;
nocache_headers();
$post = new JSON_API_Post();
$post = $res;
return array(
'post' => $post
);
}
Here you have the Table structure:
CREATE TABLE IF NOT EXISTS
wp_ws_details
(id
mediumint(9) NOT NULL AUTO_INCREMENT,device_id
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,device_type
varchar(55) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',time
datetime NOT NULL DEFAULT '0000-00-00 00:00:00', UNIQUE KEYid
(id
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1 ;
If you're getting different responses from different browsers, then there is most definitely a caching issue and it's client side. Try your function without calling nocache_headers()
and see what kind of results you get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With