FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Use of Includes
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Use of Includes [message #170907] Tue, 07 December 2010 14:55 Go to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
New to PHP.

Have searched for answer without finding anything that seems to address
it, save perhaps for situations where the script writes HTML markup
before the header is called.

When would it be preferable/required to chain scripts one to the next
rather than use includes? (The question could be reversed, also.)

Chaining:

[php] // script1.php
code;
header("location: script2.php");
[endphp]

[php] // script2.php
code;
header("location: script3.php");
[endphp]

[php] // script3.php
code;
[endphp]

Include:

[php]
// scriptname: script1.php
code;
include 'script2.php';
include 'script3.php';
[endphp]


Bill B
Re: Use of Includes [message #170908 is a reply to message #170907] Tue, 07 December 2010 15:05 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Dec 7, 2:55 pm, Bill Braun <m...@privacy.net> wrote:
> New to PHP.
>
> Have searched for answer without finding anything that seems to address
> it, save perhaps for situations where the script writes HTML markup
> before the header is called.
>
> When would it be preferable/required to chain scripts one to the next
> rather than use includes? (The question could be reversed, also.)
>
> Chaining:
>
> [php] // script1.php
>      code;
>      header("location: script2.php");
> [endphp]
>
> [php] // script2.php
>      code;
>      header("location: script3.php");
> [endphp]
>
> [php] // script3.php
>      code;
> [endphp]
>
> Include:
>
> [php]
>      // scriptname: script1.php
>      code;
>      include 'script2.php';
>      include 'script3.php';
> [endphp]
>
> Bill B

These do completely different things, so the question cannot really be
answered.

The includes cause all the scripts to be executed and then output is
sent (usually to a browser). Any global variables that are present in
script1 will have the same values in scripts 2 and 3.

The redirection using headers is supposed to be with the full url
thus:
header("location: http://www.example.com/script2.php");
header("location: http://www.example2.com/script3.php");

Script 2 knows nothing about script 1 likewise script 3. Indeed as in
my example, they could be on different servers.

You are comparing apples and pears.
Re: Use of Includes [message #170946 is a reply to message #170907] Sat, 11 December 2010 12:42 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/7/2010 9:55 AM, Bill Braun wrote:
> New to PHP.
>
> Have searched for answer without finding anything that seems to address
> it, save perhaps for situations where the script writes HTML markup
> before the header is called.
>
> When would it be preferable/required to chain scripts one to the next
> rather than use includes? (The question could be reversed, also.)
>
> Chaining:
>
> [php] // script1.php
> code;
> header("location: script2.php");
> [endphp]
>
> [php] // script2.php
> code;
> header("location: script3.php");
> [endphp]
>
> [php] // script3.php
> code;
> [endphp]
>
> Include:
>
> [php]
> // scriptname: script1.php
> code;
> include 'script2.php';
> include 'script3.php';
> [endphp]
>
>
> Bill B

I'm not sure I fully understand your question, but I'll try. First,
though, php is server side and provides html code that is presented to
the browser. So, whether you write all the code in one file, or use
includes/requires thus breaking it into two or more files, makes no
difference as far as the browser is concerned. It sees the same thing,
the whole page, either way.

I would chain scripts if there is a logical division of the actions.
For example, suppose it is a networking kind of thing and one page would
be user information for registration. This would then shift to another
page for upload of pictures after successful registration. Those are
two separate actions which are related to each other and putting them on
the same page would be cluttering. (This was a poor example because I
would just have a button with a link to a page to upload pictures after
registering and winding up on a landing page -- but it illustrates my
point).

I hope I understood your question correctly enough to be of some help.

--
Shelly
Re: Use of Includes [message #170947 is a reply to message #170946] Sat, 11 December 2010 12:58 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/11/2010 7:42 AM, sheldonlg wrote:
> On 12/7/2010 9:55 AM, Bill Braun wrote:
>> New to PHP.
>>
>> Have searched for answer without finding anything that seems to address
>> it, save perhaps for situations where the script writes HTML markup
>> before the header is called.
>>
>> When would it be preferable/required to chain scripts one to the next
>> rather than use includes? (The question could be reversed, also.)
>>
>> Chaining:
>>
>> [php] // script1.php
>> code;
>> header("location: script2.php");
>> [endphp]
>>
>> [php] // script2.php
>> code;
>> header("location: script3.php");
>> [endphp]
>>
>> [php] // script3.php
>> code;
>> [endphp]
>>
>> Include:
>>
>> [php]
>> // scriptname: script1.php
>> code;
>> include 'script2.php';
>> include 'script3.php';
>> [endphp]
>>
>>
>> Bill B
>
> I'm not sure I fully understand your question, but I'll try. First,
> though, php is server side and provides html code that is presented to
> the browser. So, whether you write all the code in one file, or use
> includes/requires thus breaking it into two or more files, makes no
> difference as far as the browser is concerned. It sees the same thing,
> the whole page, either way.
>
> I would chain scripts if there is a logical division of the actions. For
> example, suppose it is a networking kind of thing and one page would be
> user information for registration. This would then shift to another page
> for upload of pictures after successful registration. Those are two
> separate actions which are related to each other and putting them on the
> same page would be cluttering. (This was a poor example because I would
> just have a button with a link to a page to upload pictures after
> registering and winding up on a landing page -- but it illustrates my
> point).
>
> I hope I understood your question correctly enough to be of some help.
>

Here is a better example. There was an application questionnaire that
had the user's basic information and then ten separate areas of
question. Each of the ten areas data was held in a separate database
table which was linked to the user in the table of users. The first
screen gathered the basic user information (name, address, etc.) and the
submit put the data into the user table along with a page count. It
then presented the next page which was the next area of the
questionnaire. Those data were then put into its db table, the page
count was updated, and the landing page was the next area of the
questionnaire -- and so on. (The page count was so that a user could
stop and return later to where he left off). This is a good example of
chaining.

--
Shelly
Re: Use of Includes [message #170953 is a reply to message #170947] Sat, 11 December 2010 16:35 Go to previous message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
On 12/11/2010 7:58 AM, sheldonlg wrote:
> On 12/11/2010 7:42 AM, sheldonlg wrote:
>> On 12/7/2010 9:55 AM, Bill Braun wrote:
>>> New to PHP.
>>>
>>> Have searched for answer without finding anything that seems to address
>>> it, save perhaps for situations where the script writes HTML markup
>>> before the header is called.
>>>
>>> When would it be preferable/required to chain scripts one to the next
>>> rather than use includes? (The question could be reversed, also.)
>>>
>>> Chaining:
>>>
>>> [php] // script1.php
>>> code;
>>> header("location: script2.php");
>>> [endphp]
>>>
>>> [php] // script2.php
>>> code;
>>> header("location: script3.php");
>>> [endphp]
>>>
>>> [php] // script3.php
>>> code;
>>> [endphp]
>>>
>>> Include:
>>>
>>> [php]
>>> // scriptname: script1.php
>>> code;
>>> include 'script2.php';
>>> include 'script3.php';
>>> [endphp]
>>>
>>>
>>> Bill B
>>
>> I'm not sure I fully understand your question, but I'll try. First,
>> though, php is server side and provides html code that is presented to
>> the browser. So, whether you write all the code in one file, or use
>> includes/requires thus breaking it into two or more files, makes no
>> difference as far as the browser is concerned. It sees the same thing,
>> the whole page, either way.
>>
>> I would chain scripts if there is a logical division of the actions. For
>> example, suppose it is a networking kind of thing and one page would be
>> user information for registration. This would then shift to another page
>> for upload of pictures after successful registration. Those are two
>> separate actions which are related to each other and putting them on the
>> same page would be cluttering. (This was a poor example because I would
>> just have a button with a link to a page to upload pictures after
>> registering and winding up on a landing page -- but it illustrates my
>> point).
>>
>> I hope I understood your question correctly enough to be of some help.
>>
>
> Here is a better example. There was an application questionnaire that
> had the user's basic information and then ten separate areas of
> question. Each of the ten areas data was held in a separate database
> table which was linked to the user in the table of users. The first
> screen gathered the basic user information (name, address, etc.) and the
> submit put the data into the user table along with a page count. It then
> presented the next page which was the next area of the questionnaire.
> Those data were then put into its db table, the page count was updated,
> and the landing page was the next area of the questionnaire -- and so
> on. (The page count was so that a user could stop and return later to
> where he left off). This is a good example of chaining.
>

Thank you, Shelly, very helpful.

Bill B
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Best PHP Groupware Tools Script Sharing
Next Topic: newbie question
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 20:19:05 GMT 2024

Total time taken to generate the page: 0.02383 seconds