Stats

Wow, I tried a MILLION solutions to this,
and some of them worked...almost...perfectly...
and along the way I learned A LOT,
including some awesome JavaScript and PHP logic, URL sniffers, decision makers, GLOBALS, and so on...
but now, of course, the TRUE solution,
and duh, of course, it's SIMPLE, the SIMPLEST

Scenario, AJAX framework,
loads external pages into a div in the framework,
we don't want said external pages loaded by themselves, that is, their URLs should be visit-able...

Solution:
when AJAX function that loads an external page calls for it,
it also submits with its request a form, or a variable, to the page being loaded in,
page being called looks for that variable,
and without it, follows another line of action,
DUH!

example using Prototype AJAX functions:

AJAX.Updater Version:
button or link on framework base main page calls this function below, sending the variable camefromhome (could be anything), with a value of camefromhome (again, could be anything), requesting that page_to_load be loaded into the div_to_fill div:

This was a real hunt.
Built a framework.
Load everything into it with AJAX.
Don't want visitors to be able to hit PHP content pages on their own.

$_SESSION variables work, but only on first hit.
If, for example, they came from a Google search result, it would force them into the framework,
but if they hit Back and then selected another result,
it wouldn't!

Global variables work for included php file content,
but are not accessible from php code loaded in via AJAX.

$_SESSION["PHP_SELF"] for the loaded content php page is the same with or without the framework,
it's simply that script's location on the server

Finally!
$_SESSION['REQUEST_METHOD'] seems to do the job.

if ( $_SERVER['REQUEST_METHOD'] == "POST" )
{
// echo "loaded inside the framework, all clear";
// this is because I SET the AJAX functions to POST!
}
else
{
// forward into the framework based
// based on $url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
// see forwarding post
// url method here is GET because page outside the framework is simple index.php?id=12 or similar!
// but logic works even if /another_page.php is
// loaded because the METHOD isn't POST

//Check if we are using internet explorer.
try {
//If the javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using internet explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
//Else we must be using a non-internet explorer browser.
xmlhttp = false;
}
}

//If we are using a non-internet explorer browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
alert ("You are using Microsoft Internet Explorer.");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
alert ("You are using Microsoft Internet Explorder");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
alert ("You are not using Microsoft Internet Explorer");
}