How to send exit; comand to other location?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

How to send exit; comand to other location?

Post by ljCharlie »

Is there a way to send the exit; command to a location on the .php file? Here's what I'm trying to do. I want a login page. If the user failed to have the proper authorization, I want to terminate the page from displaying. However, I want to execute the php Exit command at the very end of the </html> tag. Is this possible? The problem of not doing this is that any javascript that comes after the php exit command will not get executed if the php exit command is in the middle of the page. So this is why I like to know if there is a way to exit the exit at the very end of any code.

I have tried function calling...but only to find out that the exit command will get excuted at the location of the function calling and not the location of where the exit command is written.

Any help is greatly appreciated.

ljCharlie
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

well of course. just do something like this

Code: Select all

<?php
//temp IF statement.. replace with whatever it is you are trying to use...
if($password != $mypassword)
{
?>
html data here....
Javascript Here....
html data here....

</html>
<?php
    exit;
}
?>
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Many thanks for your help. I guess I can use that if there is no other work around.

ljCharlie
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Well, after looking at my code again, it would be hard to do as you suggested. There are four or five places that I test and user the exit command. It would be hard to incorporate to that many tests.

ljCharlie
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

well, post your code and maybe we can get a better understanding of what you are trying to do? might help us in coming up with a solution at least
Post Reply