Home »
Imported messages »
comp.lang.php »
php include question
php include question [message #172149] |
Wed, 02 February 2011 00:14 |
Bill[1]
Messages: 1 Registered: February 2011
Karma:
|
Junior Member |
|
|
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?
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...
Thanks.
|
|
|
Goto Forum:
Current Time: Sun Nov 10 15:03:21 GMT 2024
Total time taken to generate the page: 0.04700 seconds