简体   繁体   English

直接HTML页面访问被拒绝

[英]Direct html page access denied

Can any one tell me how can I prevent my html page to be access directly through URL I want it to be acccess by login members only actually my page contain an image(this page is developed on word press) which refers to html page and this page needs to be access by login member only. 谁能告诉我如何防止我的html页面直接通过URL访问,我希望登录成员只能访问它,但实际上我的页面包含一个图像(此页面是在word上开发的),它指向html页面,该页面仅需要登录成员访问。 Can any one suggest any javascript code for it I have used following script: 有人可以为我建议使用以下脚本的任何JavaScript代码吗:

if (document.referrer.indexOf('flipbook_signup/wp-admin/profile/') == -1) 
{ 
   alert("Please Login!"); 
   top.location="http://google.com";
}   

But its alerting a message in both conditions. 但是在两种情况下都会发出警报。 Any other solution? 还有其他解决方案吗?

It would be difficult to do this by javascript, there you need to know or the user is logged in ... You could add some PHP code (could be different for WP) in your HTML page: 用javascript很难做到这一点,您需要知道或者用户已经登录...您可以在HTML页面中添加一些PHP代码(对于WP可能有所不同):

<?php if ( $user_ID ) : // if logged in ?>

.... here your HTML code    
<?php else : // if not logged in go to login page 

    $url = 'register';
    header("Location:$url"); 

endif; // end if logged in
?>

And in .htaccess (allow php code in html): 并在.htaccess中(允许html中的php代码):

<Files *.html>
ForceType application/x-httpd-php
</Files>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM