how to website only can access from iframe

Viewed 2693

Can anyone please help me? I have these websites: domain.com, domain.com/site2, domain.com/site3,and site4.domain.com. Site 1,2 and 3 are wordpress and site4 is php website. In site 1(domain.com) I create a side panel and my goal is that when a user accesses all my sites they still can use my side panel, so I embed/iframe site2,3 and 4 on page site 1 using advance iframe pro. How do I make site 2,3 and 4 only can open or access from site 1? For example, I iframe/embed site 2 in domain.com/mypage so that when a user opens domain.com/mypage, site 2 will open via iframe. But when a user accesses direcly from domain.com/site2, they will redirect to site1(domain.com/mypage) or they only see blank page. I tried to modify .htaccess as follows:

{

order deny,allow
deny from all
allow from domain.com/site2/12345

}

and in iframe: [iframe src="domain.com/site2/12345"]

but its not working. When I access direcly using url domain.com/site2 it shows 404 on site1, and when I access directly domain.com/site2/12345 it can open site2, but in iframe it shows 404 site1... (not use https:// whe use https:// it show 404 site1 but when only use www.domain.com/site2/12345 it can open site2)

1 Answers

I think I know what you are trying to do, in which case I think this will work but I haven't tested it (apply for other iframes and domains as you see fit).

site 2/3/4.com

if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == 'http://domain1.com') {
    include_once('sidebar.php');
} else {
    header('Location: http://domain1.com');
}

site1.com

<iframe src="http://domain2.com" frameborder="0"></iframe>

I may have got the requirements wrong, but this should show your sidebar content if there is a referrer, and if not, it will redirect to domain1.com.

A more robust way (in case the referrer is not populated for some reason) might be to add a url parameter to the iframe src attribute, e.g.

<iframe src="http://domain2.com?iframe=1" frameborder="0"></iframe>

and then check for that

if (isset($_GET['iframe']) && $_GET['iframe'] == '1') {
    include_once('sidebar.php');
} else {
    header('Location: http://domain1.com');
}

but that is also easily manipulated, a better way may be to come up with a token/hash to use instead.

Related