Hi
I've been working on a site for 6 months and have used the header command to redirect loads and loads of times. But i just noticed some crazy behaviour today. Heres a test page:
<?php
include("includes/db_connect.php");
header('location:stores.php');
$sql = "insert into test (id) values (77)";
$result = mysql_query($sql);
?>
when i hit this page, i get redirected to stores.php, but the sql gets executed! Is this supposed to be the behaviour? Have i completely missed the point of header(location:)?? Im baffled as i've used this before, but only now noticed this crazy behaviour!
everything executes after a header location!?
Moderator: General Moderators
-
Zander1983
- Forum Newbie
- Posts: 20
- Joined: Mon Mar 21, 2011 2:26 pm
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: everything executes after a header location!?
Best practice is to put an exit(); after a header(location:) to prevent further script execution.
-
Zander1983
- Forum Newbie
- Posts: 20
- Joined: Mon Mar 21, 2011 2:26 pm
Re: everything executes after a header location!?
that worked, thanks. Ive been using header(location) for years without knowing this! thanks!
Re: everything executes after a header location!?
Answer to both is yes.Zander1983 wrote:Is this supposed to be the behaviour? Have i completely missed the point of header(location:)??