Ok, so I have PHP set upp to ato_prepend and auto_append files to every script
I run. So if I someone surfs to /index.php, these scripts run:
init.php -> set up DB connections and stuff. Buffers output
index.php -> The current page with it's layout, output is buffered.
postprocess.php -> Fetches buffer, applies layout to page.
Now, sometimes I want to break the execution of index.php (or whatever page
that is in the middle). For example, when someone submits a form with
insufficient data, I want to quit executing code and just put up an alert. But
if I use "die;", then PHP will stop executing all code, it won't just stop
executing the code in index.php.
Is there a way to tell PHP to stop executing code in the current script, but
continue with the next? I would guess that the same could apply to include()'d
files, where I want the execution of the included file to stop, but the page
that included the file shouldn't stop executing. I.e.:
<?
print "Hello ";
include("world.php");
print "!";
?>
And "world.php" would in this case just output "World", but by using some
method, I could just break the execution of world.php from within world.php
(without using large IF blocks) and the result would then be "Hello !" from the
page, and not "Hello " which happens if I use "die;" in world.php.
Any suggestions?
--
Sandman[.net] 6 4003
Sandman wrote: Any suggestions?
Perhaps you could use something like:
<?php
while (true) {
// ...
if ( NOT_ALL_FIELS_CORRECT ) {
$message = ERRORMSG;
break;
}
// Rest of code
break; // Don't forget this or you're thrown in an infinite loop
}
?>
--
Pieter Nobels
In article <jH***********************@phobos.telenet-ops.be>,
Pieter Nobes <pi******@MOVE.opengate.be> wrote: Sandman wrote: Any suggestions?
Perhaps you could use something like:
<?php while (true) { // ... if ( NOT_ALL_FIELS_CORRECT ) { $message = ERRORMSG; break; } // Rest of code break; // Don't forget this or you're thrown in an infinite loop } ?>
I don't get it. How do I apply this to my files? In which file do I add this? I
would very much prefer not to have index.php (in this case) be something like:
if (condition){
(alert of error and break script
} else {
huge block of application, several K's big that would ordinarely be executed
}
--
Sandman[.net]
Sandman wrote: In article <jH***********************@phobos.telenet-ops.be>, Pieter Nobes <pi******@MOVE.opengate.be> wrote:
Sandman wrote:
Any suggestions? Perhaps you could use something like: ...
I don't get it. How do I apply this to my files? In which file do I add this? I would very much prefer not to have index.php (in this case) be something like:
You use it in all your pages. You start a while loop (just an example,
first possible way I could think of), and when something goes wrong, you
/break out/ out the wile loop, and the other script (postproccess.php)
will be executed (since that code isn't in the while loop). Process:
load page
include init.php
execute init.php
go into while loop
check wether $_GET['name'] is empty
$_GET['name'] is empty, break out of while loop the rest of the code in the while loop isn't executed, since we
broke out
include postprocess.php
execute postprocess.php
if (condition){ (alert of error and break script } else { huge block of application, several K's big that would ordinarely be executed }
Why don't you want this? You *have* to say *somewhere* what the
interpreter has to in which conditions. This seems like a very good and
fast solution (beter than the while loop ;-) )
--
Pieter Nobels
In article <ES***********************@phobos.telenet-ops.be>,
Pieter Nobes <pi******@MOVE.opengate.be> wrote: Sandman wrote: In article <jH***********************@phobos.telenet-ops.be>, Pieter Nobes <pi******@MOVE.opengate.be> wrote:
Sandman wrote:
Any suggestions?
Perhaps you could use something like: ...
I don't get it. How do I apply this to my files? In which file do I add this? I would very much prefer not to have index.php (in this case) be something like: You use it in all your pages. You start a while loop (just an example, first possible way I could think of), and when something goes wrong, you /break out/ out the wile loop, and the other script (postproccess.php) will be executed (since that code isn't in the while loop). Process:
load page include init.php execute init.php go into while loop check wether $_GET['name'] is empty $_GET['name'] is empty, break out of while loop >>>> the rest of the code in the while loop isn't executed, since we
broke out include postprocess.php execute postprocess.php
if (condition){ (alert of error and break script } else { huge block of application, several K's big that would ordinarely be executed }
Why don't you want this? You *have* to say *somewhere* what the interpreter has to in which conditions. This seems like a very good and fast solution (beter than the while loop ;-) )
Ok, before I set up and start trying this, are you saying that I could initiate
the loop in init.php and end it in postprocess.php? Like this:
init.php
print "Hello";
while (true){
index.php
if (!$_GET["name"]) break
print "Index";
postprocess.php
break;
}
print "World!";
So if the IF in index.php fails, will it only print "HelloWorld!"? What if I
have a loop in index.php and want to break from that? That is, if you can even
set a loop to span several scripts...
I am using the apache option php_append_file and php_prepend_file to include
init.php and postprocess.php to all scripts.
--
Sandman[.net]
Sandman wrote: So if the IF in index.php fails, will it only print "HelloWorld!"? What if I have a loop in index.php and want to break from that? That is, if you can even set a loop to span several scripts...
No, that's not possible. You'd have to do it in every script. I think
this solution is better because if you'd use if/else you'd have almost
*no* space left because of indenting... i.e.:
<?php
if (empty($var1)) break;
else {
// do some things
if ($connection == false) break;
else {
// do some things
if ($numrows = 0) break;
else {
// ...
}
}
}
?>
which would, in the end, become *VERY* unclear.
--
Pieter Nobels
Pieter Nobes wrote: Sandman wrote:
Any suggestions?
Perhaps you could use something like:
<?php while (true) { // ... if ( NOT_ALL_FIELS_CORRECT ) { $message = ERRORMSG; break; } // Rest of code break; // Don't forget this or you're thrown in an infinite loop } ?>
The manual available at php.net uses a do-while loop to do the same
thing, except that with a do-while loop, you don't have to worry about
infinite loops if you use do { // ... } while(0);
<?php
do {
// ...
if ( BOZO_CANNOT_FILL_OUT_FORMS_CORRECTLY ) {
$message = ERRORMSG;
break;
}
// ...
} while (0);
?>
Here's the part of the php.net manual I'm talking about : http://www.php.net/manual/en/control...s.do.while.php This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Roland Dalmulder |
last post by:
Hello all,
In my PHP script I put a text file into a string. Part of that string is
read, changed and removed. The while loop continuest to extract the next
part of the string. This goes all...
|
by: Michele Simionato |
last post by:
Is there a way of "ending" a module? I would like something like this:
# mod.py
print 'something here'
end() # some mysterious function
print 'you should not get here'
# main.py
import mod...
|
by: Ann |
last post by:
I have trouble sometimes figuring out where
break and continue go to. Is there some easy
way to figure it out, or a tool?
TIA
Ann
|
by: Ed |
last post by:
Hoping someone an assist me urgently. I would truly appreciate and help.
I have a form and prices are based on 'price break'.
1.The price break fields work fine, but I cannot for the life of me...
|
by: Jianli Shen |
last post by:
const DInst *stopAtDst = 0;
while (dinst->hasPending()) {
if (stopAtDst == dinst->getFirstPending())
break; ///////break? break? break? is this break outof the whole
while loop and...
|
by: PHaroZ |
last post by:
Hi,
I want to retrieve the complete full path to the directory
of my current page but i don't find how to do that.
For example i want : D:\myWebSite\firstDotNetWebApp\dir1\
I tried...
|
by: Sonnich Jensen |
last post by:
Hi!
I have a page, including a while, which can read quite an amount of
data, if the user selects so.
I want to add something, so I can break this while - I havent found it
yet.
I have tried...
|
by: suga.masanobu |
last post by:
Hello group.
I have thread in which I perform specific task in loop. I can specify,
by check box, in what periods of time that task should be done, ex.
instantly, with 5min break, with 15min...
|
by: DanielT |
last post by:
i'd like to print bar codes with page break after each bar code, below is my current codes.
Protected Sub cmdGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |