Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different response from different browser

Tags:

wordpress

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 KEY id (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1 ;

like image 280
Govinda Yadav Avatar asked Feb 08 '17 08:02

Govinda Yadav


1 Answers

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.

like image 108
Spartacus Avatar answered Oct 28 '22 18:10

Spartacus