admin管理员组文章数量:1431413
i am trying to restrict particular web page using php which should be displayed only to the allowed Ip Addresses and for remaining all IP Address it should not be accessible.
Requirement:
1.The page will be in sub menu list.
2.It should be displayed only to the allowed ip address only
Thank You in advance....
i am trying to restrict particular web page using php which should be displayed only to the allowed Ip Addresses and for remaining all IP Address it should not be accessible.
Requirement:
1.The page will be in sub menu list.
2.It should be displayed only to the allowed ip address only
Thank You in advance....
Share Improve this question edited Feb 28, 2017 at 12:53 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 28, 2017 at 11:52 PraveenPraveen 2405 silver badges19 bronze badges 1- How are you trying that? Show us your code. – fuxia ♦ Commented Feb 28, 2017 at 12:54
2 Answers
Reset to default 1Haven't specifically done this yet but something similar
In the theme page/post template files you can get post id of current post/page by doing
$currentID = get_the_ID();
Then redirect all traffic not from the specified IPs
$ipArr = array('xx.xxx.xxx.xxx', 'xx.xxx.xxx.xxx');
if (!in_array(@$_SERVER['REMOTE_ADDR'], $ipArr))
{
header("Location: http://example/myhomepage");
die();
}
You can block the access page for all IPs, but a whitelist.
function page_ip_restriction() {
if(is_page('yourpage'))
{
// Whitelist
$whitelist = array(
'127.0.0.1',
'127.0.0.2',
'127.0.0.3',
);
// Check if current user IP is out of the whitelist, then redirect to home
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist))
{
wp_redirect(home_url(), 403); // 403 -> Forbiden access
exit();
}
}
}
add_action('init', 'page_ip_restriction', 10);
For your submenu, you have two ways, the wordpress one, or a css exclusion. But IMO, WordPress menus are really heavy to use.
If you want better IP address tracking, use a librairy.
Hope it's help you !
本文标签: How can we Restrict to access a certain wordpress page to all ip address except some which we allow
版权声明:本文标题:How can we Restrict to access a certain wordpress page to all ip address except some which we allow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572268a2664116.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论