php Clickjack保护

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Clickjack保护相关的知识,希望对你有一定的参考价值。

/**
 * The HTTP header X-Frame-Options: SAMEORIGIN should be set.
 *
 * Older browsers do not support the X-Frame-Options header, so the following
 * JavaScript will act as a workaround.
 */
try { top.document.domain } catch (e) {
	var f = function() {
		document.body.innerHTML = '';
	};
	setInterval( f, 1 );
	if ( document.body ) {
		document.body.onload = f;
	};
}
<?php
/**
 * Clickjacking projection for old browsers
 *
 * Header not supported by older browsers, use JS fallback.
 **/
 function mwtsn_example_wp_enqueue_scripts() {
	$script_url = plugins_url( 'js/clickjack-protection.js', __FILE__ );
	wp_enqueue_script(
		'clickjack-protection-js',
		$script_url,
		array( 'jquery' ),
		'',
		true
	);
	// Clickjack headers not supported below IE8.
	wp_script_add_data( 'clickjack-protection-js', 'conditional', 'lt IE 8' );
}
add_action( 'wp_enqueue_scripts', 'mwtsn_example_wp_enqueue_scripts, 10 );
<?php
/**
 * Clickjacking protection
 *
 * Add header to stop site loading in an iFrame.
 **/
function mwtsn_example_send_headers() {
	header( 'X-FRAME-OPTIONS: SAMEORIGIN' );
}
add_action( 'send_headers', 'mwtsn_example_send_headers', 10 );

以上是关于php Clickjack保护的主要内容,如果未能解决你的问题,请参考以下文章

Php代码如何实现代码保护,不被窃取?

保护 PHP 网页访问

如何保护 php 脚本?

PHP PHP令牌保护

php 安全保护与私有

php电子表格密码保护