php include question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.

 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. </
<!--  the cut line for the header -->
 <title>Logged in</title>
you are logged in and the resources is here and blah blah...


<?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


Re: php include question

On 2/1/2011 7:14 PM, Bill wrote:
Quoted text here. Click to load it

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.

Re: php include question

El 02/02/2011 1:14, Bill escribió/wrote:
Quoted text here. Click to load it

You don't need the else part. Just show whatever error message you want
and exit the script.


if( !$logged_in ){
     // ...

Quoted text here. Click to load it

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline