English 中文(简体)
Large PHP file containing multiple pages vs Multiple PHP files with the use of session variables
原标题:

What are the advantages/disadvantages of using include/require s to achieve a singular file that contains multiple pages as opposed to directing the user to many individual pages and storing the variables as session variables?

In particular I am asking with regard to a long multi step process (think questionnaire).

最佳回答

If you re including the code of very single page to render one of them:

  1. You re loading and parsing tons of code that you re not going to use for every request
  2. Any parse error introduced into any one of those files will cause your whole site to come down

The first PHP app I inherited used the "include everything" strategy. There was an immediate, obvious performance gain when I transitioned it to only loading code that was actually going to be used.

问题回答

Personally I love using includes and requires to construct your page.

The part where you draw the line is including everything.

Let s say I have a web app that let s people resize photos online, on the homepage I would include the header, a sidebar, the homepage content area, and a footer.

The main part to focus on here is the homepage content area, if they were on the homepage there would be no point to include or require the file that handles the functions for resizing images.

If you would like a real world example of includes and requires and how effective they are, check out any Wordpress blog. I have a few clients that have wanted to use Wordpress as a CMS and to this day they still function superbly even with tons of data and user flowing through them.

Also, this subject has been covered multiple times, feel free to check out: One large include file or several smaller ones?

Hope this helps.

You might get better answers if you could be more specific about what particular technical concerns you have about the two approaches or what you are looking for.

Choosing one approach over the other is much more related to interaction design than about PHP. Check this Web Pattern Library. You usually use a Wizard or multi-paged form when

the user wants to achieve a single goal but several decisions need to be made before the goal can be achieved completely, which may not be known to the user.

A multipage questionnaire that collects pages in topics and presents them to the user on page by page basis might be helpful for them to better focus on the topic at hand.

Apart from that, splitting the page might yield benefits in transfer and rendering times, but unless you are sending a 2MB questionnaire, this is hardly an issue if you use HTTP compression. If there is no PHP in the included files you might also just fpassthru them, so PHP does not need to parse the files.





相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签