Jump to content

[SOLVED] a file can only used if inside another php file


chadrt

Recommended Posts

I am building a dispatch system for a roadside assistance company from scratch.  It is interesting as I have never had a project this big before and my knowledge of php is sub-beginner.

 

I am doing ok so far but I have a page that authenticates users after a login form sets a cookie.  This form calls other pages into it using

 

include($page.".php")

 

but those pages  can be called individually and I want them to be rendered useless unless they are called from within the main page.  Thank you for your help.

Link to comment
Share on other sites

in your include file put this at the top

 

<?php

if ($fileaccess != "allow") {

    exit('No direct access allowed');

}

?>

 

then you will not be able to direct access. Then in your index put

 

$fileaccess = "allow";

include($page.".php")

 

 

Link to comment
Share on other sites

Ok quick question what I do something like this?

 

<?php
if ($fileaccess9 != "allowRR783") {
     header("Location: index.php");
}
?>

 

Because the index is a redirect to the login page which also check for cookie existence and will redirect them to the dispatch system main page if it exists, isnt expired and the user has not been suspended in the system.

 

If I do this is this fail safe?  Or is there some level of security I should be aware of doing it this way?

 

Thanks again for your help...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.