Stopping the use of a URL to get to the site

时间:2015-10-30 23:38:18

标签: javascript html url

So I have a website which redirects to another part of the site ie, when pressing a button on "www.test.com" it reditects to "www.test.com/anotherpage". Now my problem is that I only want users to be able to access the second page when using the button and not just typing in "www.test.com/anotherpage" into the search bar. So, is there any way to setup my page such that it cannot be accessed by the url but only redirected from another part of the website?

4 个答案:

答案 0 :(得分:0)

document.referrer The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). Since this property returns only a string, it does not give you DOM access to the referring page.

答案 1 :(得分:0)

您需要使用Php代码登录用户并查看会话示例,例如exaplain:Login form and session example 当然你需要基本了解Php

答案 2 :(得分:0)

您可以使用客户端服务器端口技术。

客户端的示例是Javascript,读取被调用页面中的document.referrer @Barmar指出,并且如果引荐来源不是来自您的主页,则重定向到主页。

服务器端方式可以使用传递给页面的参数,例如将在主页上生成的SESSION标识符,并在被调用页面中进行检查。

实际上,有不同的方法来实现您的目标。 您应该提供有关环境的更多信息,以便我们提供帮助。

答案 3 :(得分:0)

你可以使用PHP。只需将您的按钮放在表单标签之间

即可
<form action="http://www.test.com/anotherpage" method="POST">
   <input name="mybutton" type="submit" value="Go to another page">
</form>

和另一页

<?php 
 if (!isset($_POST['mybutton'])) { //check if the button was clicked
    header('Location: index.html'); //forward to index if not
 }
?>