【发布时间】:2021-03-01 18:26:05
【问题描述】:
您好,我的问题是将对 wordpress 网站的某些 url 的访问限制为单个引用域的最佳方法是什么。 据我熟悉javascript,我找到了一种方法。但我认为javascript代码不好,因为页面的源代码没有改变。 我写了这段代码:
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
document.body.style.display="none";
var url = document.referrer;
var domainname;
var referal_code = getCookie("protect_faq_pages");
console.log(url);
if(url){
var anchor = document.createElement("a");
anchor.href = url;
domainname = anchor.host;
console.log(domainname);
if(domainname == "softwareservicetech.com"){
var cookieString = "protect_faq_pages=cWs@fgf$a1fD#FsC-)";
document.cookie = cookieString;
}
}else if(!(referal_code == "cWs@fgf$a1fD#FsC-)")){
document.getElementById("page").innerHTML="<p>Sorry you do not have permission to view the content</p>"
}
console.log(referal_code);
document.body.style.display="block";
这个网站可以自己访问: https://health-unity.com/ 您可以发现下面的页面在视图上受到限制: https://health-unity.com/help-centre/videos/ 还有这些页面: https://health-unity.com/help-centre/videos/video-number-2/ https://health-unity.com/help-centre/videos/video-number-1/ 但是当单击以下站点上的链接时(链接到 health-unity-videos): https://softwareservicetech.com/testpage/ 之后可以访问存档页面。用户可以直接进入以下页面: https://health-unity.com/help-centre/videos/video-number-2/ https://health-unity.com/help-centre/videos/video-number-1/ 这些以前受到限制,现在可以通过设置的 cookie 访问。 但问题是页面源仍然存在并且没有被javascript代码更改,用户可以查看页面源。我还希望隐藏 cookie 值。由于这两个问题,我认为 javascript 不是一个好主意。 如果有 javascript、php 或编辑 functions.php 或 .htaccess 文件来实现这一点,请与我分享。 感谢您提前回复
【问题讨论】:
标签: javascript php html wordpress .htaccess