Reply to Re: Brackets across includes

Your name:

Reply:


Posted by Jerry Stuckle on 12/17/95 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?
>
> Thanks very much, in advance.
>
> -- Whit Nelson
>

Whit,

The easiest way I've found doesn't require functions or anything else.
It also allows you to have the authorization only those pages which
require it.

authorize.php:

<?php
if (!isset($_SESSION['loggedon']) || $_SESSION['loggedon != true']) {
header('/logon.php');
exit();
}
?>

This checks the $_SESSION['loggedon'] variable to see if it is set and
true. If so, the process allows the rest of the page to be displayed.
If not, it redirects the user to 'logon.php'.

Change the test as necessary for your system. Then just

include('authorize.php')

at the very start (before anything - even DOCTYPE or white space) of any
php file requiring authentication.

No function calls to fool with, no worries about mismatched braces, etc.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация