|
Posted by Rik on 12/10/54 11:56
pengypenguin@gmail.com wrote:
> Hello all,
>
> I am trying to create a user authentication system, and I would like
> to separate the authentication code into include files. As I see it,
> the basic flow would go something like this:
>
> if (not authentic) {
> display login
> } else {
> display content
> }
>
> I would like to separate this code so that the login bit is in an
> included file. I imagined the breakup like this:
>
> file: [auth_head.php]
> -----------------------
> if (not authentic) {
> display login
> } else {
> -----------------------
>
> file: [auth_foot.php]
> -----------------------
> }
> -----------------------
>
> So in each file which requires authentication, I can simply include
> the first bit in the head, the second bit at the bottom, and put the
> content in the middle. Makes sense, right?
>
> Unfortunately, it seems that you cannot continue a { bracket }
> statement across includes in this manner, as php errors. (It wants you
> to wrap up your brackets before the end of the file.)
>
> Does anyone know of a solution to this problem, or perhaps a
> work-around?
In cases users not logged in may not see the whole page, I just:
if(not authentic){
header('HTTP/1.0 401 Unauthorized');
/* or alternatively you could redirect to the/a login page :
header('Location: http://www.example.com/login.php'); */
exit;
}
//rest of code, which will not be displayed or run. No need for brackets
Grtz,
--
Rik Wasmus
[Back to original message]
|