require_once

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: require_once

Post by flying_circus »

eazyGen wrote:He included a header and a footer, which seems fine. Except to say that in the included header file there were divs opened but not closed. He relied on the included footer to close them.

This is actually pretty common, and depends on your application design. For example, if I include a header file that contains the html and head elements, I would probably need to include a footer file to close the body and html elements.

For open divs, it's probably a wrapper used to control the site layout. I do this on almost every project.


As with every risk, you need to consider your exposure. How often would you expect to be able to include a header file, and then have the footer go missing?
User avatar
eazyGen
Forum Commoner
Posts: 46
Joined: Mon Aug 29, 2011 4:32 am
Location: Central London

Re: require_once

Post by eazyGen »

flying_circus wrote:
eazyGen wrote:He included a header and a footer, which seems fine. Except to say that in the included header file there were divs opened but not closed. He relied on the included footer to close them.

This is actually pretty common, and depends on your application design. For example, if I include a header file that contains the html and head elements, I would probably need to include a footer file to close the body and html elements.

For open divs, it's probably a wrapper used to control the site layout. I do this on almost every project.


As with every risk, you need to consider your exposure. How often would you expect to be able to include a header file, and then have the footer go missing?
I am not so much concerned that the footer might go missing - there would be a big error if it did, and I could then fix that. My concern is that, by using this technique, you have open (and hidden) div blocks that could be closed inadvertently. The app would then misbehave and it would not be immediately apparent why.

You mention risk. When building an app (of any size and in any language), I don't look to minimise risk, I seek to annihilate it.

My approach has always been (and will almost certainly still be when using PHP) to create self-contained files only, as far as is possible.

S
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: require_once

Post by flying_circus »

I am pretty certain that we all code to annihilate risk, but anyone who has been doing this for a while will agree that it is impossible to achieve 100%. The important bit is what happens when it does fail. The risk in this case, is displaying a non well formed web page. Something that might be visually displeasing, but it wont be a security blunder.

When you use the technique properly, it is pretty easy to visually see when it fails, typically parts of your page will shift. If you are left scratching your head, I would advise using a debugging tool, like the w3c validator. All of us understand the importance of writting a well formed html document and it's not hard to do.

To sit here and say that one way is right and the other is wrong is foolish. It's simply a different way to approach a problem. Just another tool for getting the job done.
User avatar
eazyGen
Forum Commoner
Posts: 46
Joined: Mon Aug 29, 2011 4:32 am
Location: Central London

Re: require_once

Post by eazyGen »

flying_circus wrote:I am pretty certain that we all code to annihilate risk, but anyone who has been doing this for a while will agree that it is impossible to achieve 100%. The important bit is what happens when it does fail. The risk in this case, is displaying a non well formed web page. Something that might be visually displeasing, but it wont be a security blunder.

When you use the technique properly, it is pretty easy to visually see when it fails, typically parts of your page will shift. If you are left scratching your head, I would advise using a debugging tool, like the w3c validator. All of us understand the importance of writting a well formed html document and it's not hard to do.

To sit here and say that one way is right and the other is wrong is foolish. It's simply a different way to approach a problem. Just another tool for getting the job done.
Thanks for the advice, but I have been coding using a variety of languages since the mid 1980's and creating error free code has been a habit of mine since then.

You seem to be saying that an error that is "visually displeasing" is ok, but an error that is a "security blunder" is not. I simply do not agree. Both represent errors, both can be fixed, and both should be.

I do agree that there is often no absolute right and wrong with code. But I do know that to have errors is wrong and not to have errors is right. And to not have a file that you have explicitly stated you want (include) or worse, need (require) is an error in my book.

S
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: require_once

Post by flying_circus »

eazyGen wrote:You seem to be saying that an error that is "visually displeasing" is ok, but an error that is a "security blunder" is not.
No, this is how you want to interpret what I am saying.

I am not interested in discussing personal semantics in such a black and white fashion. Good luck to you.
User avatar
eazyGen
Forum Commoner
Posts: 46
Joined: Mon Aug 29, 2011 4:32 am
Location: Central London

Re: require_once

Post by eazyGen »

flying_circus wrote:
eazyGen wrote:You seem to be saying that an error that is "visually displeasing" is ok, but an error that is a "security blunder" is not.
No, this is how you want to interpret what I am saying.

I am not interested in discussing personal semantics in such a black and white fashion. Good luck to you.
And to you.

S
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

Re: require_once

Post by Lphp »

I learn form all replies thank!
Post Reply