[nycphp-talk] automatic redirection of PHP script
ali mohammad
ali at vpproperty.com
Tue Oct 23 12:26:41 EDT 2007
Based on your pseudo code, I am probably assuming you want to terminate
the rest of the current script when it conditionally branches to one of
your branch scripts. If so, make sure it does.
Your pseudo code should more closely resemble the below statements if
what I presumed is correct.
=======================================================================
//script begin
//script code common to all conditions...
If ($cost < 100) {
//execute branch script-a.php (could be with a header statement)
//exit current script
} else if ($cost > 1000) {
//execute branch script-b.php (could be with a header statement)
//exit current script
} else {
//carry on with the rest of the script.
}
...
//script code only applicable to the third 'default' case if any
//script end
========================================================================
You can also consider an alternative approach based on Jon's solution
that obviates the need for specific exit statements with header()
redirections (and the additional work that may be involved with pushing
potential GET/POST data you want to send to that redirected script if
you are not or decide not to pass the data via session variables).
//script begin
//common script code applicable to all three cases...
Switch (true) {
Case ($cost < 100):
include 'script-a.php';
break;
Case ($cost > 1000)
include 'script-b.php';
Break;
Default:
//Put in all specific statements that need to be executed
//when $cost fails to meet above two conditions
}
//common script code applicable to all three cases
//end of script
Regards,
Ali Mohammed.
On Oct 23, 2007, at 4:13 AM, PaulCheung wrote:
> Hi
>
> I was wondering if anybody knows? I am sure that others must have
> encountered this in the past. What I am trying to accomplish is a
> conditional exit from the current script, go to and execute
> another script without any manual intervention. Using the following
> pseudo code, I am fully aware it is not elegant but it serves to
> explain what I want to accomplish.
>
> If $Cost < 100 goto and execute script-a.php
> else
> if $Cost > 1000 goto and execute script-b.php
> else
> carry on;
>
> Normally I would be happy to supply real PHP coding but
> unfortunately I do not know how to execute what I want to.
>
> Paul
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com
Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php
More information about the talk
mailing list