what is the correct/nice way to exit php CGI script running on a web server?
From: Alex Hunsley (lard_at_tardis.ed.ac.molar.uk)
Date: 07/26/04
- Next message: Chung Leong: "Re: isset(), empty(), $_GET and $_POST problem"
- Previous message: Chung Leong: "Re: detecting REFRESH through PHP"
- Next in thread: steve: "Re: what is the correct/nice way to exit php CGI script running"
- Reply: steve: "Re: what is the correct/nice way to exit php CGI script running"
- Reply: Gordon Burditt: "Re: what is the correct/nice way to exit php CGI script running on a web server?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jul 2004 00:45:54 GMT
I'm making a web site that does login authentication.
It all works fine, but I have a question about 'correctness'...
Certain php scripts on the site should only run in the user has logged
on. So, the 'private' scripts in question all includes the following php
script:
<?
// has user authenticated?
if (! $logged_in) {
$newPath='login.php';
echo "<html><head><meta http-equiv=\"REFRESH\" content=\"3;
url=$newPath\"></head>";
echo "<body>You can't access this page without logging
in!<p>Redirecting to the <a href=\"$newPath\">login page</a> in 3
seconds.</body></html>";
}
// exit php so that no more content gets output!
exit(0);
?>
As you can see, if the user is not logged on, we output an http refresh
to redirect the users browser to the login screen. It works fine, but my
main question is about the trick of calling exit(0) at the end, which is
required to stop the php script that includes the above code from
outputting any of its content (which is 'secret' from unauthenticated
users.)
Is calling exit(0) ok to this end? Is it considered a dirty hacky way of
doing it? It does the job, but I'm just wondering if there is a nicer
way of doing it I should be using.
thanks
alex
- Next message: Chung Leong: "Re: isset(), empty(), $_GET and $_POST problem"
- Previous message: Chung Leong: "Re: detecting REFRESH through PHP"
- Next in thread: steve: "Re: what is the correct/nice way to exit php CGI script running"
- Reply: steve: "Re: what is the correct/nice way to exit php CGI script running"
- Reply: Gordon Burditt: "Re: what is the correct/nice way to exit php CGI script running on a web server?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|