Pioden Posted November 11, 2008 Share Posted November 11, 2008 Hi folks. First off I'm having a bad day (and know it) so sorry if this turns out to be something REALLY dumb. I'm coding a basic user authentication system - like I've done many times before. However this time things are not working in a way I expect! For simplicity's sake lets say I have two files - index.php and session.php. Session does the authentication. In index.php I 'require_once' session.php - that works! In session.php I have just this: <?php session_start(); if (!isset($_SESSION["defnyddiwr"])) { echo "login box"; exit(); } ?> The result is that the unauthenticated user gets show 'login box' but also the HTML in index.php - exit() seems to have no effect! I was expecting the script to stop at the exit point - including index.php!! What on earth is going wrong? I could have sworn I've used this method in the past without any problems. Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/ Share on other sites More sharing options...
BioBob Posted November 11, 2008 Share Posted November 11, 2008 See if it isnt making it to exit() by exit("exited out") or something. I think it accepts an argument to just display then quit... Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687654 Share on other sites More sharing options...
Pioden Posted November 11, 2008 Author Share Posted November 11, 2008 No joy. It echoed login textexited out and continued as before. Strange huh! Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687661 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Have you tried die("exited out"); Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687667 Share on other sites More sharing options...
Pioden Posted November 11, 2008 Author Share Posted November 11, 2008 Have you tried die("exited out"); Thanks for the suggestion. Just tried it now and the result is the same - index.php continues to execute as if nothing happened. Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687673 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 ok, first off then add error_reporting(E_ALL); ini_set('display_errors','On'); to the top of the page, just in case there is an error we can't see then if there are no errors try <?php echo "test"; exit(" did work"); echo " didn't work"; ?> And see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687677 Share on other sites More sharing options...
Pioden Posted November 11, 2008 Author Share Posted November 11, 2008 Interesting! It returned this login texttest did work and then all the index.php stuff. No errors. Seems like exit(); stops the execution of session.php but not index.php even though it's an included file. Is this normal? I'm 99% sure I've used this method before without this problem. Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687689 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Ahh, i'm not sure if file inclusion will exit the page you are viewing, i believe the exit works but only on the page it's in, not when included. If that makes sense, <?php //page 1 echo"test"; exit(); echo"stopped"; ?> <?php //page 2 include "page1.php"; echo "<br>test2"; ?> That code will stop anything after the exit on page 1 being sent to page 2, but the exit won't affect page 2. Quote Link to comment https://forums.phpfreaks.com/topic/132272-exit-unexpected-result/#findComment-687693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.