PHP code example of unvurn / http-user-agent

1. Go to this page and download the library: Download unvurn/http-user-agent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

unvurn / http-user-agent example snippets


    // Controller
    
    // api function that processes request from UnityPlayer
    public function get(Request $request) {
        $userAgent = $request->getUserAgent();
        if (!$userAgent->hasProduct("UnityPlayer")) {
            throw new BadRequestException("access allowed for UnityPlayer only");
        }

        // regular process
        
        return response()->json([
            // ...        
        ]);
    }

    // if you want to check "AppleWebKit" version:
    // ex) Windows 10/11
    //     Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
    public function get(Request $request) {
        $userAgent = $request->getUserAgent();
        if ($userAgent->product("AppleWebKit")?->version !== "537.36") {
            throw new BadRequestException("latest AppleWebKit version