Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php problem, exit function.

Options
  • 29-07-2006 12:54am
    #1
    Registered Users Posts: 689 ✭✭✭


    Hi

    Does the exit command in php completely stop the php processing and should it cause html outside php tags to NOT be included in a served up file?

    The closing body and html tags aren't included in the served up page because of the php exit command EVEN THOUGH the missing text is outside the php tags. Is this supposed to happen?

    PHP Source
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php echo 'Section 1<br>'; ?>

    <?php exit("Dead<br>");
    echo 'Section 1.5<br>'; ?>

    <?php echo 'Section 2<br>'; ?>

    </body>
    </html>


    PHP Output (to the browser)
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    Section 1<br>Dead<br>


    Any help would be very handy.
    Cheers
    Joe


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    You can attempt to use return() instead of exit, but I don't think it'll work.

    You're better of using conditionals to control what's being output.


  • Closed Accounts Posts: 22,479 ✭✭✭✭philologos


    I'm nearly sure that exit(); was replaced with die(); at some point.
    Exit and Die are both meant to stop the PHP file from processing yes and why do you need so many <?php tags right beside eachother why not use one for the whole lot

    Seamus is right though, you should use conditionals (if's or switch) unless its absolutely neccessary to use die


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I think die() and exit() are pretty much equivalent.

    die() is pretty much meant to be used in cases where processing can't or shouldn't continue. For example, if you detect that someone has passed malicious arguments to your script. It's quite often used in database-driven sites if the script fails to connect to the database or server - if the script continues processing, it may output errors and warnings which would reveal variable names and details of your code.
    Better off to simply issue a die() with a message to the user.


  • Closed Accounts Posts: 22,479 ✭✭✭✭philologos


    yeah i've only ever seen die beside MYSQL connections or socket connections


Advertisement