Skip to content

Detect device by custom header. #5

@kawaz

Description

@kawaz

For example, this is Amazon CloudFront.
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device

CloudFront don't send User-Agent to backend. But It can send the custom headers instead of User-Agent.

  • CloudFront-Is-Desktop-Viewer
  • CloudFront-Is-Mobile-Viewer
  • CloudFront-Is-SmartTV-Viewer
  • CloudFront-Is-Tablet-Viewer

Now, I add like this code.

if ( ! $this->device ) {
    if ($_SERVER['HTTP_CLOUDFRONT_IS_DESKTOP_VIEWER') == "true" ) { /* do nothing */ }
    elseif ($_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER') == "true" ) { $this->device = "smart"; }
    elseif ($_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER') == "true" ) { $this->device = "tablet"; }
    elseif ($_SERVER['HTTP_CLOUDFRONT_IS_SMARTTV_VIEWER') == "true" ) { $this->device = "game"; /* ??? */ }
}

Really, I want to configure the list of set of header name and matching value on /wp-admin/, but it is very hard for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions