Home »
Imported messages »
comp.lang.php »
php include question
Re: php include question [message #172157 is a reply to message #172149] |
Wed, 02 February 2011 08:15 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 02/02/2011 1:14, Bill escribió/wrote:
> I have many (hundreds) html files that I need to put some logic to
> check whether the user logged in or not. So I add php code to check
> the cookie, which is set when the user sign in. The following is the
> sample php file.
>
> ============================================================
> <?php
> if ( (!isset($_COOKIE['uid'])) )
> {
> ?>
> <html><head><title>you are not logged in</title></head><body>
> You are not logged in so you are not able to access this resource.</
> br>
> </body></html>
> <?php
> }
> else
> {
> ?>
> <!-- the cut line for the header -->
> <html>
> <head>
> <title>Logged in</title>
> </head>
> <body>
> you are logged in and the resources is here and blah blah...
>
> </body>
> </html>
>
> <?php } ?>
>
> ====================================================
> I am trying to create a header.php with the first lines all the way to
> the<!-- the cut line for the header -->
> and then include it in the other php files.
>
> The reason I want to create a header.php file is that the real logic
> is actually more complex than this example. I will need to only
> change one file instead of hundereds or thousands files when we need
> to change the logic. And also for the new pages, I can ask the
> developer to add only one line in each of the html file like:
> <?php include('header.php'); ?>
>
> But when I access the php file which includes the header.php, in the
> error log, it says:
>
> PHP Parse error: syntax error, unexpected $end in /var/www/html/
> library/header.php on line 13
> I know that is probably because in the header.php the if - else is
> not closed yet. Here come my questions:
>
> 1) any good way to do what we want to do?
You don't need the else part. Just show whatever error message you want
and exit the script.
<?php
if( !$logged_in ){
// ...
exit;
}
> 2) seems to me that the included php file should be logically self-
> contained? - in the example, the if - else logic is split into two
> files...
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|
Goto Forum:
Current Time: Sun Nov 10 14:55:31 GMT 2024
Total time taken to generate the page: 0.04979 seconds