You are here: Re: Brackets across includes « PHP Programming Language « IT news, forums, messages
Re: Brackets across includes

Posted by Rik on 10/26/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

 

Navigation:

[Reply to this 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

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