Re: php include question [message #172150 is a reply to message #172149] |
Wed, 02 February 2011 00:42 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 2/1/2011 7:14 PM, Bill 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?
> 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.
No, don't try to split the if -else logic into two files. You need to
keep it all in one file.
And BTW - cookies are not a good way to see if someone is logged in. A
hacker can easily create a cookie with an administrator's id and have
all kinds of access. Rather, use a session (since the session id, while
stored in a cookie, is a long, pseudo-random string which changes with
each session).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|