I've been searching Google and here, and haven't found anything that'd work for me. I'm trying to restrict access to my scripts so that they will only be accessible via the main page. On the initial page load, everything loads fine. But, if I click on a link, the define() variable I have in my main page is no longer defined to other things, so it causes a failure. Perhaps code will be more helpful.
index.php:
<?php
session_start();
define('CRC32', microtime());
@require_once('funcs.php');
?>
[...]
<div id="header">
<div style="width: 20%; float: left;"><img src="img/logo.gif" alt="S4U Logo" /></div>
<div id="login_form" style="width: 80%; float: right; text-align: center;"><?php require('forgotpw.php'); ?></div>
[...]
funcs.php:
<?php
function CheckAllowed(){
if(!constant('CRC32')){
echo("<script>alert('fail');</script>");
//header("HTTP/1.1 404 Not Found");
}
}
?>
forgotpw.php:
<?php
@require_once("funcs.php");
CheckAllowed();
if(!isset($_SESSION['key'])){
echo("HI2!");
} else{
echo("HI!");
//echo("<script>alert('You are currently logged in.');</script>");
}
?>
I just edited this to show you, but "Forgot Password?" (forgotpw.php) is actually a link.
Basically CheckAllowed() works fine when you first go to the website, but when you click on the "Forgot Password?" link, it calls forgotpw.php and CheckAllowed() fails because CRC32 is no longer defined (I've tested this with the if() statements, forgotpw.php will load right now, but will show the "fail" dialog box as CRC32 isn't defined anymore). I've also tried not doing it via a function and putting the code right in there, but I still have the same issue.
Does anyone have any idea on how to get this to work with Ajax? I've heard of using $_SERVER as a workaround, but I haven't found anything that illustrates what to do w/ the server variables.