Click to See Complete Forum and Search --> : File Direct Access Disable


Jick
07-19-2003, 12:53 AM
I have my site (http://kd7pyo.infinitypages.com/) and on it you will notice that I have a Iframe. The links on the page open up in the Iframe. I wundered if there was a php script that would not allow direct access of the files. The links are Home, About Us, Examples, etc... If you were to go to http://kd7pyo.infinitypages.com/examples.php you could access that page without going to it through the Iframe. I want to make it so if they try to access the page directally it will redirect them to the main index page. I want it so the only way you can access the pages such as examples.php is through the Iframe. Is this possible?

pyro
07-19-2003, 07:39 AM
This is a rather old thread, but it might help you along. I've got to leave soon, or I'd try to get you something a bit closer to what you need...

http://forums.webdeveloper.com/showthread.php?s=&threadid=2111#post10273

Jick
07-19-2003, 10:57 AM
Well since Pyro's gonna be gone can someone else help me?

the_idiot
07-19-2003, 01:55 PM
I am very new to both PHP and JavaScript so I can't give syntax specifics, but here are two solutions that may work.

When the user clicks on a link call a JavaScript function that writes a cookie with name="mylink" value="1". On the page you want loaded into the IFrame set up a selection like so:

$access=$_COOKIE['mylink'];
if ($access==1) {
//print your page
} else {
//redirect to homepage
echo '
<script language=javascript>
window.location.href="www.mysite.com/";
</script>'
}


Alternatively, you could pass the value via a query string.

Also, you may be able to use JavaScript on the pages to be loaded into the IFrame to see if a parent node for the IFrame exists, then use

document.body.innerHTML="myhtml";

However, this method is only good if the pages are to contain no server-side scripts.

I haven't actually tried either of these, so I'm not sure they work.

Sorry I can't provide more actual code, but maybe the above will give you some ideas.

pyro
07-19-2003, 09:57 PM
Here it is in psuedo-code:

1: Check if the current page is equal to the main page (ie. the page that contains your iframe.) A simple comparison with $_SERVER["PHP_SELF"] should be enough.

2: If the page is NOT equal to the top page, use a header redirect ( header("Location:http://www.yourdomain.com/yourpage.php?page=$_SERVER['PHP_SELF']"); ) to send it back to the page to the main page with a query string attached.

3: On yourpage.php check if a query string is set ( if(isset(_GET["page"])) { )

4: If it is, set up the frameset with the page in the query string set as the src of the iframe, if not, set it up with the default page...

Da Warriah
07-20-2003, 08:18 AM
what if, on the main page, you simply give the iframe page a variable, like send the page as page.php?id=1...so if its not loaded in the iframe, it gets loaded without that variable...

then set up some if statements:

if($id == 1){

// display page

} else {

header(Location: index.php);

}

that should work, should it not?

pyro
07-20-2003, 08:58 AM
Yeah, and I thought about that, but decided to give the other version. If you are interested in that way, this might help you: http://www.infinitypages.com/research/divinclude.php

Jick
07-21-2003, 02:43 AM
Sorry, I kinda got lost. Will you show me the code all put togeather. I see the diffewrent peices you posted and I tried to put them togeather but I screwed that up. Just post the code and explain what pages the codes go on. Thanks. :D