This article introduces the use of the new CSS3 feature web-font, and uses custom web-font to prevent data collection
Introduction to web-font
web-font is a tag @font-face in CSS3. In the @font-face declaration, you can declare a font and specify this The font library file is downloaded from a certain address on the Internet.
The specific writing method is as follows:
@font-face { font-family: '字体名称'; src: url('http://www.example.com/字体名称.eot'); /* IE9 Compat Modes */ src: url('http://www.example.com/字体名称.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('http://www.example.com/字体名称.ttf') format('truetype'), /* Safari, Android, iOS */ url('http://www.example.com/字体名称.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */ url('http://www.example.com/字体名称.svg?#字体名称') format('svg'); /* Legacy iOS */}
When web page data needs to be modified with a special font, we can use web-font. Because using web-font will automatically load the font from the network, the user does not need to have the font installed on the machine.
Use custom web-font to prevent data collection
Prevention principle:
Use web-font to load fonts from the network, so we can create a set of fonts ourselves and set up a custom character mapping table.
For example, set 0xaaa to map character 1, 0xbbb to map character 2, and so on.
When the character 1 needs to be displayed, the source code of the web page will only be 0xaaa, and the collected data will only be 0xaaa, not 1, so that the collector cannot collect correct data. There is no impact on users with normal access.
It is not suitable to use the web-font method to prevent Chinese collection, because the Chinese font library is too large. For numbers and English, this method is suitable for preventing collection.
Example: Use custom web-font to prevent digital data collection (such as stocks, movie box office and other data)
1. Create a custom font of specified characters
First select a font. For convenience of demonstration, select the Arial font that comes with the system.
ttf to svg
Enter everythingfonts.com/ttf-to-svg
Upload the ttf file and convert the font file Convert to svg format and save as my_webfont.svg
Select the characters to be used and set the font mapping relationship
Enter icomoon.io/app/#/select
Select the Import Icons button in the upper left corner and import my_webfont.svg
After importing, select the characters we want to use. In this example, we only need to select 0-9, and then click the lower right corner Generate Font Button
Set character mapping
Arial font character mapping relationship (characters and hexadecimal)
0 => 301 => 312 => 323 => 334 => 345 => 356 => 367 => 378 => 389 => 39
We modify it here The mapping relationship can be as complex and irregular as possible to make it difficult to guess.
For example, set the mapping relationship to
0 => e1f21 => efab2 => eba33 => ecfa4 => edfd5 => effa6 => ef3a7 => e6f58 => ecb29 => e8ae
and modify the name according to the mapping relationship. After setting the mapping relationship, click the lower right corner downloadDownload font.
Name all downloaded font files as my_webfont.*
2. Use web-font in web pages Display data
First you need to set @font-face
@font-face { font-family: 'my_webfont'; src: url('fonts/my_webfont.eot?fdipzone'); src: url('fonts/my_webfont.eot?fdipzone#iefix') format('embedded-opentype'), url('fonts/my_webfont.ttf?fdipzone') format('truetype'), url('fonts/my_webfont.woff?fdipzone') format('woff'), url('fonts/my_webfont.svg?fdipzone#my_webfont') format('svg');}
Then you need to define a css class, font-family uses this web-font
.my_webfont{ font-family: my_webfont !important; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;}
Where this kind of data needs to be displayed, fill in the data, and the class of the container is defined as my_webfont
<p class="my_webfont"></p>
so that the character 1 can be displayed.
3. Complete example code
<?php// 字体映射关系function get_font_num($num){ $result = ''; $font_map = array( 0 => 'e1f2', 1 => 'efab', 2 => 'eba3', 3 => 'ecfa', 4 => 'edfd', 5 => 'effa', 6 => 'ef3a', 7 => 'e6f5', 8 => 'ecb2', 9 => 'e8ae' ); for($i=0,$len=strlen($num); $i<$len; $i++){ $n = substr($num, $i, 1); if(is_numeric($n)){ $result .= '&#x'.$font_map[$n].';'; }else{ $result .= $n; } } return $result; }$data = array( array('金刚:骷髅岛', 4921.98, 5), array('美女与野兽', 971.36, 12), array('欢乐喜剧人', 590.27, 5), array('一条狗的使命', 389.76, 26), array('领袖1935', 271.27, 1), );?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>利用自定义web-font实现数据防采集</title> <style type="text/css"> @font-face { font-family: 'my_webfont'; src: url('fonts/my_webfont.eot?fdipzone'); src: url('fonts/my_webfont.eot?fdipzone#iefix') format('embedded-opentype'), url('fonts/my_webfont.ttf?fdipzone') format('truetype'), url('fonts/my_webfont.woff?fdipzone') format('woff'), url('fonts/my_webfont.svg?fdipzone#my_webfont') format('svg'); font-weight: normal; font-style: normal; } .my_webfont{ font-family: my_webfont !important; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } td{ padding: 0px 5px 0px 5px; text-align: center; } .left{ text-align: left; } </style> </head> <body> <table> <tr> <td>排名</td> <td>片名</td> <td>实时票房(万)</td> <td>上映天数</td> </tr><?php for($i=0,$len=count($data); $i<$len; $i++){ echo '<tr>'.PHP_EOL; echo '<td>'.($i+1).'</td>'.PHP_EOL; echo '<td class="left">'.$data[$i][0].'</td>'.PHP_EOL; echo '<td class="my_webfont">'.get_font_num($data[$i][1]).'</td>'.PHP_EOL; echo '<td class="my_webfont">'.get_font_num($data[$i][2]).'天</td>'.PHP_EOL; echo '</tr>'.PHP_EOL; }?> </table> </body></html>
You can see normal data when accessed in the browser
But the html source code is actually
<tr><td>1</td><td class="left">金刚:骷髅岛</td><td class="my_webfont">.</td><td class="my_webfont">天</td></tr>
The collector can only get something like edfd; data cannot know what characters are mapped by edfd;, thus preventing data collection.
Of course, the collector can know the meaning of each mapping through analysis, so as to perform post-collection conversion processing.
We can create multiple different font files and mapping tables. Each visit randomly uses one type, and regularly updates a batch of font files and mapping tables to increase the difficulty of collection.
In this way, the collector needs to analyze and convert all font files and mapping tables before collecting data, which will greatly increase the cost of collection.
The above is the detailed content of Use custom web-font to implement data collection prevention code. For more information, please follow other related articles on the PHP Chinese website!

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

In PHP, trait is suitable for situations where method reuse is required but not suitable for inheritance. 1) Trait allows multiplexing methods in classes to avoid multiple inheritance complexity. 2) When using trait, you need to pay attention to method conflicts, which can be resolved through the alternative and as keywords. 3) Overuse of trait should be avoided and its single responsibility should be maintained to optimize performance and improve code maintainability.

Dependency Injection Container (DIC) is a tool that manages and provides object dependencies for use in PHP projects. The main benefits of DIC include: 1. Decoupling, making components independent, and the code is easy to maintain and test; 2. Flexibility, easy to replace or modify dependencies; 3. Testability, convenient for injecting mock objects for unit testing.

SplFixedArray is a fixed-size array in PHP, suitable for scenarios where high performance and low memory usage are required. 1) It needs to specify the size when creating to avoid the overhead caused by dynamic adjustment. 2) Based on C language array, directly operates memory and fast access speed. 3) Suitable for large-scale data processing and memory-sensitive environments, but it needs to be used with caution because its size is fixed.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In JavaScript, you can use NullCoalescingOperator(??) and NullCoalescingAssignmentOperator(??=). 1.??Returns the first non-null or non-undefined operand. 2.??= Assign the variable to the value of the right operand, but only if the variable is null or undefined. These operators simplify code logic, improve readability and performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment