zuc0001
zuc0001

Reputation: 930

PHP/JQUERY Defining an included page

I have a website where pages are loaded dynamically inside of a DIV container using JQUERY.

            $("div#container div.content div.main").load(siteLink+"/"+newloadVal);

It works great, however, I am looking for a way to stop visitors from accessing these included pages THROUGH their actual weblinks such as site.com/pagelink.php.

My main question is, is there a way to do a similar PHP define("THROUGHJS,true); using Javascript, so if the visitor accesses the included page through its actual link, it will redirect to an error page?

Is there an easy way to do this, mainly through JUST PHP?


I have not attempted this, but is this possible:

In the parent page, have DEFINE("mainpage",true),

then in the dynamically loaded page, have:

if(defined("mainpage")){
...}
else { exit; } // Show an error?\

I am not sure if this is possible as the dynamic page is not being loaded via PHP, therefore the defined function in the parent page will not "exist" to the dynamic page?

Thanks for any help in advance. (Sorry if this may seem confusing) :P

Upvotes: 0

Views: 51

Answers (2)

zuc0001
zuc0001

Reputation: 930

EDIT: I ended up going with an AJAX request, that way I can use request headers to determine if the page was loaded using AJAX or not.

Thanks for all your help guys :)

Upvotes: 0

EyalAr
EyalAr

Reputation: 3170

A possible semi-solution:
Generate a unique key for a user's session and pass it to all requests to the additional pages.
For each request of an additional page through jquery, include this key as a query parameter (or as post data). When the required page is loaded, check if the key matches the user's session. If not, display an error.
Something like this:

$("...").load(siteLink + "/" + newloadVal + "?key=<?php echo $session_key ?>");

This will not actually prevent users from directly accessing your pages, but it will require them to know a valid key. For this the (average user) will have to visit the main page, look at the source, find the key, etc.

Upvotes: 1

Related Questions