Same code to be used in multiple pages

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
bghayad
Forum Newbie
Posts: 9
Joined: Thu Oct 29, 2009 1:13 pm

Same code to be used in multiple pages

Post by bghayad »

Hi All;

I have a form (which make a search for some data based on the selections and so on), I need to use this form in alot of pages, but it is not practical to keep put the code in each of these pages, and if I did any change on the code then I have to copy this code for all the pages ... it is really hard work.

Any suggested method to be placed in one place and use it in different pages, so I maintain it in this place only without need to keep copy for each change?

Any help?
Regards
Bilal
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Same code to be used in multiple pages

Post by aravona »

Generally you'd use a function. You can make php code to run a section of HTML, using echo's - and you can then make this an include.php file, and just include this file at the top of your page and run the function in a section of php where you need it.
functions basics
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Same code to be used in multiple pages

Post by McInfo »

aravona's suggestion can be simplified by taking a more direct approach and placing the include statement where the form is to be inserted. Additional functions and echo statements are unnecessary.

PHP Manual: include()

Edit: This post was recovered from search engine cache.
Post Reply