visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Using exit function


By: PHP newbee U.S.A.  Date: 25/07/2003 00:00:00  English  Points: 20 Status: Answered
Quality : Excellent
I was wondering if theres another way to exit after validation!
where i put the ************* below i want to exit if it reaches that validation without finishing the include page but everytime i use exit function it exits continuing the home page text to display???
how can i exit just the include page????



example

Im using a page index.php for example


<?php
include 'test.php';
?>

<b> My Home page</b>


==============

<?php
//(test.php)

if ($variable ==123){
echo "123";
*************************************
}

if (isset($HTTP_SESSION_VARS['logged_user'])){
echo "user logged in";
}


?>

By: VGR Date: 26/07/2003 20:59:00 English  Type : Answer
require your "include file" in stead of including it

see doc
By: jamesm87 Date: 26/07/2003 21:26:00 English  Type : Comment
Create it in functions and call it with the exit at the end (Function for HTML,Test). If you do not understand let me know and I will explain otherwise this should work
By: PHP newbee Date: 26/07/2003 21:50:00 English  Type : Comment
>>require your "include file" in stead of including it
>>see doc

What are u talking about?


>>Create it in functions and call it with the exit at the end (Function for HTML,Test). If >>you do not understand let me know and I will explain otherwise this should work

do you mean create a function and then use exit to exit from the function?



By: jamesm87 Date: 26/07/2003 22:48:00 English  Type : Comment
yes... or call a new function.
By: wtgee Date: 27/07/2003 19:51:00 English  Type : Comment
Do you want to just do one or the other? As in

if ($variable ==123){
echo "123";
} else {
if (isset($HTTP_SESSION_VARS['logged_user'])){
echo "user logged in";
}
}

When you are using exit it is stopping all processing when it hits the exit, meaning that it will not continue on with your home page.
By: PHP newbee Date: 27/07/2003 19:53:00 English  Type : Comment
is there just a way to exit just the include page only!
By: wtgee Date: 27/07/2003 20:07:00 English  Type : Comment
What do you mean by exit the include page? You mean you don't want to include the rest of it if the first test passes?
By: PHP newbee Date: 27/07/2003 20:29:00 English  Type : Comment
Comment from wtgee
Yes exactly i just want to validate the first test then exit if it fails!!!

By: wtgee Date: 27/07/2003 21:28:00 English  Type : Comment
Well, if you do the if...else statement I listed above it will accomplish the same thing. You don't really lose anything by loading the rest of the include file as long as it doesn't run (which the if....else statement prevents). If you really don't want it loaded you could do the if....else statement but put another include in the else instead of the code. That way if it never hits the else it will not load the rest of the text.
By: basvg Date: 28/07/2003 21:04:00 English  Type : Comment
Like VGR said, don't do:

include('test.php');

but do a:

require('test.php');

instead.

If you want to stop parsing in the middle of an included file (you need include in this case), you can just enter return, like so:

return;

If you enter an

exit;

in a require'd page, the script will stop pasing completely.
(Haven't tested this, but that's what the docs say.)

By: PHP newbee Date: 28/07/2003 21:37:00 English  Type : Comment
ausome i should give the points to him im sorry i just assumed the require wouldnt work i guess why the hell would i come here if i know everything?
i'll try it next time someone suggests something!
By: VGR Date: 28/07/2003 21:42:00 English  Type : Comment
yes, please do :D :D
By: basvg Date: 28/07/2003 22:05:00 English  Type : Comment
Actually I was just using exit() in an included file and got the required results... ;-)


Do register to be able to answer

EContact
browser fav
page generated in 409.001830 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page