Home  >  Article  >  Backend Development  >  Methods to prevent web pages from being referenced by iframes in PHP, Nginx, and Apache_PHP Tutorial

Methods to prevent web pages from being referenced by iframes in PHP, Nginx, and Apache_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:44917browse

You can use php or nginx to add the X-Frame-Options header to control frame permissions
X-Frame-Options has three optional values:

DENY: The browser refuses the current page to load any Frame page
SAMEORIGIN: The address of the frame page can only be the page under the same origin domain name
ALLOW-FROM: The page address that allows the frame to be loaded

PHP code:

Copy code The code is as follows:
header('X-Frame-Options:Deny');

Nginx configuration:

Copy code The code is as follows:
add_header X-Frame-Options SAMEORIGIN

can be added to the location

Copy code The code is as follows:
location /
{
add_header X-Frame -Options SAMEORIGIN
}

Apache configuration:

Copy code The code is as follows:

Header always append X-Frame-Options SAMEORIGIN

After using it, a whiteboard will be displayed on pages that do not allow frames.

Reference:

https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options?redirectlocale=en-US&redirectslug=The_X-FRAME-OPTIONS_response_header

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781033.htmlTechArticleYou can use php or nginx to add X-Frame-Options header to control frame permissions. There are three X-Frame-Options Optional values: DENY: The browser refuses the current page to load any Frame page SAMEORI...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn