When ajax is used, we can know that ajax can trigger an interface across domains, but this causes a problem that any domain can call. in this case, we need to consider using anti-Leech technology.
When ajax is used, we can know that ajax can trigger an interface across domains, but this causes a problem that any domain can call. in this case, we need to consider using anti-Leech technology, in PHP, $ _ SERVER ["HTTP_REFERER"], $ _ SERVER ["HTTP_REFERER"] contains the URL of the previous page linked to this page, if you come in directly, $ _ SERVER ["HTTP_REFERER"] has no value. The following is a simple example to describe how PHP creates and submits data against counterfeiting:
The interface called by non-9streets.cn is Access denied:
PHP code
- // Judge refer to prevent other domain calls
- $ Refer = $ _ SERVER ['http _ referer'];
- If ($ refer ){
- $ Url = parse_url ($ refer );
- If ($ url ['host']! = '9streets. cn '){
- Exit ('Access denied! ');
- }
- }
Methods that can be called between subdomains
PHP code
- // Judge refer to prevent other domain calls
- $ Refer = $ _ SERVER ['http _ referer'];
- If ($ refer ){
- $ Url = parse_url ($ refer );
- $ T = explode ('.', $ url ['host']);
- $ L = count ($ t );
- $ DomainStr = $ t [$ L-2]. '.'. $ t [L-1];
- If ($ domainStr! = '9streets. cn '){
- Exit ('Access denied! ');
- }
- }