...

View Full Version : Including functions that may or may not be used



matak
08-10-2007, 07:17 PM
Hy peeps. Having fun? :)

My problem is not in php code, but in using the same code. Site i'm working on uses $_GET to move through pages, and on one page i have a contact form. Few days i thought of how to use the contact.php that lays in my includes folder to load only on contact forms page.

Problem is that my code isn't extendable to that level, and i can't find a proper way to include that contact function only on my contact form, so i thought of just including it in the index file, and some ppl i asked told me that is ordinary habit of including all function in index file.

For some reason i don't think that is a good idea, couse first it loads lot's of unnecessary code, and maybe somehow it can be a good path to further errors in code.

So what do you guys think, to just include the function, or to recode everything and find a proper way of including the contact.php only when contact page is reached.

Thanks

PhaZZed
08-10-2007, 07:39 PM
I guess it really depends on how strong your host is. See, loading the file into memory each time obviously uses excess memory, but if the site isn't massive, then it should be ok.

The other way is to setup a permissions table, which will contain which pages have access to this contacts file you talk of, but this will still involve loading information into memory.

Using the include won't be much of a problem in my opinion.

Perhaps someone else can assist better..

matak
08-10-2007, 08:39 PM
The other way is to setup a permissions table

oh, i'm not using mySQL. in my free time i'm developing a new 4d database system.. Lol..

aedrin
08-10-2007, 11:42 PM
and i can't find a proper way to include that contact function only on my contact form

Explain that further.

Why can you not just include a PHP file on a specific page?

Just including everything on every single page is bad design and unnecessary load on the server. So I would advise against doing that.

usik
08-11-2007, 01:10 AM
Explain that further.

Why can you not just include a PHP file on a specific page?

Just including everything on every single page is bad design and unnecessary load on the server. So I would advise against doing that.

I agree with aedrin, but if you are insistent on doing it differently why not make a big class file that is require for every page with a big assortment of classes and functions one might need to use in their web app

matak
08-11-2007, 02:07 AM
Why can you not just include a PHP file on a specific page?

well my template class is rather sloppy coded. i know i can do it better, and i need few advices, so if you guys want to take a peep at it i'll post it here. I'm stuck with it couse for now it's only designed to include static pages from an array, where their titles are defined (everything is flat file). To expand it to include PHP also is a lot of work, beacoue i would like to do it in separate class, and i wouldn't even like to start it until i know that needs to be done.

Now i know, and it needs to be done. If you want to help me figure out how to make a good template class(if you can even call it template for now), i would be glad to post the code i made so far. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum