JustinK101 Posted July 23, 2010 Share Posted July 23, 2010 We just ran across something very confusing using header("Location"). Does header("Location") work just like a die() statement, in that execution stops? Because we found that execution can continue for a few lines even after hitting the header("Location"). For example, take this: <?php if(empty($_POST['username']) || empty($_POST['password'])) { header("Location: /login"); } header("Location: /home"); ?> When testing, and $_POST['username'] and $_POST['password'] were empty, we were being redirected to /home instead of /login. Link to comment https://forums.phpfreaks.com/topic/208628-does-headerlocation-behave-like-a-die-statement/ Share on other sites More sharing options...
Pikachu2000 Posted July 23, 2010 Share Posted July 23, 2010 No. You need to follow a header(); with an exit(); to stop the script from executing further. Link to comment https://forums.phpfreaks.com/topic/208628-does-headerlocation-behave-like-a-die-statement/#findComment-1089946 Share on other sites More sharing options...
JustinK101 Posted July 23, 2010 Author Share Posted July 23, 2010 Wow, that is very interesting. I wonder how many PHP applications have this security hole. Can we combine the header() and die()? Like: die(header("Location: /login")) Link to comment https://forums.phpfreaks.com/topic/208628-does-headerlocation-behave-like-a-die-statement/#findComment-1089949 Share on other sites More sharing options...
Pikachu2000 Posted July 23, 2010 Share Posted July 23, 2010 I don't know; I've never tried it . . . Link to comment https://forums.phpfreaks.com/topic/208628-does-headerlocation-behave-like-a-die-statement/#findComment-1089952 Share on other sites More sharing options...
MasterK Posted July 23, 2010 Share Posted July 23, 2010 die(header('Location:http://www.google.com/')); This does work, I have used it a few times Link to comment https://forums.phpfreaks.com/topic/208628-does-headerlocation-behave-like-a-die-statement/#findComment-1089955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.