i need to prevent visitors from opening a page outside iframe
for example
when write on browser :
www.sss.com/index.php
will be open
but when write
www.sss.com/add_news.php
i need to redirect to home page
Since an iframe makes a GET request there isn't really any way to distinguish a GET request coming from the browser itself and one coming from an iframe embedded in a page. In both cases the browser makes the same GET request. You could probably write some JavaScript code in your "iframe" page that detects whether or not it is loaded in the top window and redirects if it isn't.
From the accepted answer on How to identify if a webpage is being loaded inside an iframe or directly into the browser window?
using the window properties top
and self
<script type="text/javascript">
if (top === self) {
location = '/index.php';
}
</script>
I suggest you to generate some token eg. "982h2jruhndjf92", store it on server or in cookie then add it as GET param to the in-frame script.
<iframe src="www.sss.com/add_news.php?token=982h2jruhndjf92" />
if url provides same token you show the right view, otherwise redirect user using header() function.
using just php you could do it with the header
<?php
header( 'Location: www.sss.com/index.php' ) ;
?>