I have an IFrame inside my 1st page that loads another page which I don’t want it to be accessed directly. So I thought maybe I can be sure that the 2nd page is loaded inside 1st one if I check the top.location in 2nd page and do as normal if it’s equal 1st page URL or remember user as hacker if it’s not.
Here is the code:
1st Page:
<html>
<head>
<title>1st Page</title>
</head>
<iframe src="2nd Page" name="frame1" height="80%" width="100%"></iframe>
</html>
2nd Page:
<script type="text/javascript">
if(top.location == "1st Page URL") {
// It's OK, Access is not direct
} else {
// It's not a normal access
}
</script>
It seems that this code will work fine, but I’m not sure if it’s foolproof or not. Maybe top.location could be spoofed (like $_SERVER['HTTP_REFERER']) or it’s totally unreliable somehow. I need to be sure about that.
Well, you can use JSPs. Have your second page, the one that should never be accessed directy placed in the WEB-INF folder of your project, and then have the main page do a jsp:forward towards that resource. This way the 2nd page can never be accessed directly.