|
1 | 1 | <?php |
| 2 | + |
| 3 | +use hexydec\agentzero\agentzero; |
| 4 | + |
2 | 5 | require(__DIR__.'/src/autoload.php'); |
3 | 6 |
|
4 | 7 | // fetch UA string |
5 | 8 | $ua = $_POST['ua'] ?? $_SERVER['HTTP_USER_AGENT'] ?? ''; |
6 | 9 |
|
7 | 10 | // client hints |
8 | | -$hints = [ |
9 | | - 'sec-ch-ua-mobile' => $_POST['mobile'] ?? $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ?? '', |
10 | | - 'sec-ch-ua-full-version-list' => $_POST['browser'] ?? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] ?? '', |
11 | | - 'sec-ch-ua-platform' => $_POST['platform'] ?? $_SERVER['HTTP_SEC_CH_UA_PLATFORM'] ?? '', |
12 | | - 'sec-ch-ua-platform-version' => $_POST['platformversion'] ?? $_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] ?? '', |
13 | | - 'sec-ch-ua-model' => $_POST['model'] ?? $_SERVER['HTTP_SEC_CH_UA_MODEL'] ?? '', |
14 | | - 'device-memory' => $_POST['memory'] ?? $_SERVER['HTTP_DEVICE_MEMORY'] ?? '', |
15 | | - 'width' => $_POST['width'] ?? $_SERVER['HTTP_WIDTH'] ?? '', |
16 | | - 'ect' => $_POST['ect'] ?? $_SERVER['HTTP_ECT'] ?? '' |
| 11 | +$hints = agentzero::getHints(); |
| 12 | +$keys = [ |
| 13 | + 'sec-ch-ua-mobile', |
| 14 | + 'sec-ch-ua-full-version-list', |
| 15 | + 'sec-ch-ua-platform', |
| 16 | + 'sec-ch-ua-platform-version', |
| 17 | + 'sec-ch-ua-model', |
| 18 | + 'device-memory', |
| 19 | + 'width', |
| 20 | + 'ect' |
17 | 21 | ]; |
| 22 | +foreach ($keys AS $item) { |
| 23 | + if (!empty($_POST[$item])) { |
| 24 | + $hints[$item] = $_POST[$item]; |
| 25 | + } |
| 26 | +} |
18 | 27 | $memsizes = [ |
19 | 28 | '0.25' => '256Mb', |
20 | 29 | '0.5' => '512Mb', |
|
39 | 48 |
|
40 | 49 | // timing variables |
41 | 50 | $time = \microtime(true); |
42 | | -$output = \hexydec\agentzero\agentzero::parse($ua, \array_filter($hints)); |
| 51 | +$output = \hexydec\agentzero\agentzero::parse($ua, \array_filter($hints), ['versionscache' => __DIR__.'/cache/versions.json']); |
43 | 52 | $total = \microtime(true) - $time; |
44 | 53 | ?> |
45 | 54 | <!DOCTYPE html> |
|
104 | 113 | <h3>Client Hints</h3> |
105 | 114 | <div class="form__control"> |
106 | 115 | <label class="form__label">Mobile:</label> |
107 | | - <select name="mobile"> |
| 116 | + <select name="sec-ch-ua-mobile"> |
108 | 117 | <option value="">-- Select Mobile --</option> |
109 | 118 | <?php foreach ($devices AS $key => $item) { ?> |
110 | | - <option value="<?= \htmlspecialchars($key); ?>"<?= $hints['sec-ch-ua-mobile'] === $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
| 119 | + <option value="<?= \htmlspecialchars($key); ?>"<?= ($hints['sec-ch-ua-mobile'] ?? null) === $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
111 | 120 | <?php } ?> |
112 | 121 | </select> |
113 | 122 | </div> |
114 | 123 | <div class="form__control"> |
115 | 124 | <label class="form__label">Browser:</label> |
116 | | - <input type="text" class="form__input" name="browser" value="<?= \htmlspecialchars($hints['sec-ch-ua-full-version-list']); ?>" /> |
| 125 | + <input type="text" class="form__input" name="sec-ch-ua-full-version-list" value="<?= \htmlspecialchars($hints['sec-ch-ua-full-version-list'] ?? ''); ?>" /> |
117 | 126 | </div> |
118 | 127 | <div class="form__control"> |
119 | 128 | <label class="form__label">Platform:</label> |
120 | | - <input type="text" class="form__input--short" name="platform" value="<?= \htmlspecialchars($hints['sec-ch-ua-platform']); ?>" /> |
| 129 | + <input type="text" class="form__input--short" name="sec-ch-ua-platform" value="<?= \htmlspecialchars($hints['sec-ch-ua-platform'] ?? ''); ?>" /> |
121 | 130 | </div> |
122 | 131 | <div class="form__control"> |
123 | 132 | <label class="form__label">Platform Version:</label> |
124 | | - <input type="text" class="form__input--short" name="platformversion" value="<?= \htmlspecialchars($hints['sec-ch-ua-platform-version']); ?>" /> |
| 133 | + <input type="text" class="form__input--short" name="sec-ch-ua-platform-version" value="<?= \htmlspecialchars($hints['sec-ch-ua-platform-version'] ?? ''); ?>" /> |
125 | 134 | </div> |
126 | 135 | <div class="form__control"> |
127 | 136 | <label class="form__label">Model:</label> |
128 | | - <input type="text" class="form__input--short" name="model" value="<?= \htmlspecialchars($hints['sec-ch-ua-model']); ?>" /> |
| 137 | + <input type="text" class="form__input--short" name="sec-ch-ua-model" value="<?= \htmlspecialchars($hints['sec-ch-ua-model'] ?? ''); ?>" /> |
129 | 138 | </div> |
130 | 139 | <div class="form__control"> |
131 | 140 | <label class="form__label">Memory:</label> |
132 | | - <select name="memory"> |
| 141 | + <select name="device-memory"> |
133 | 142 | <option value="">-- Select Memory --</option> |
134 | 143 | <?php foreach ($memsizes AS $key => $item) { ?> |
135 | | - <option value="<?= \htmlspecialchars($key); ?>"<?= $hints['device-memory'] == $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
| 144 | + <option value="<?= \htmlspecialchars($key); ?>"<?= ($hints['device-memory'] ?? null) == $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
136 | 145 | <?php } ?> |
137 | 146 | </select> |
138 | 147 | </div> |
139 | 148 | <div class="form__control"> |
140 | 149 | <label class="form__label">Width:</label> |
141 | | - <input type="number" class="form__input--short" name="width" value="<?= \htmlspecialchars($hints['width']); ?>" /> |
| 150 | + <input type="number" class="form__input--short" name="width" value="<?= \htmlspecialchars($hints['width'] ?? ''); ?>" /> |
142 | 151 | </div> |
143 | 152 | <div class="form__control"> |
144 | 153 | <label class="form__label">Connection:</label> |
145 | 154 | <select name="ect"> |
146 | 155 | <option value="">-- Select Connection --</option> |
147 | 156 | <?php foreach ($conns AS $key => $item) { ?> |
148 | | - <option value="<?= \htmlspecialchars($key); ?>"<?= $hints['ect'] === $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
| 157 | + <option value="<?= \htmlspecialchars($key); ?>"<?= ($hints['ect'] ?? null) === $key ? ' selected="selected"' : ''; ?>><?= \htmlspecialchars($item); ?></option> |
149 | 158 | <?php } ?> |
150 | 159 | </select> |
151 | 160 | </div> |
|
0 commit comments