robsumner Posted November 12, 2008 Share Posted November 12, 2008 Hi guys. I apologize in advance if this is tricky to understand. I am going to try to explain it as best as I can. I am in the process of learning PHP and have a problem on my "register.php" page. The user gets entered in the database but I am trying to redirect the user to a thanks.php page after registering. I am getting this error: Warning: Cannot modify header information - headers already sent by (output started at /home/name/public_html/newsite/header.htm:7) in /home/name/public_html/newsite/register.php on line 73 My register page has an include file: include ('header.htm'); In that include file, it has its own head tag. <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title></title> <style type="text/css" media="all">@import "./includes/layout.css";</style> <link href="styles.css" rel="stylesheet" type="text/css"> </head> On my register.php page I have this code: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/thanks.php'; header("Location: $url"); exit(); So it seems that this header("Location: $url"); isn't working because I have that include in the register page. When I comment out the include file at the top of my register page it works fine and directs the user to a thanks.php page. So finally... My question is how would I make it still redirect to the thanks.php while keeping the include header? Quote Link to comment https://forums.phpfreaks.com/topic/132472-cannot-modify-header-information/ Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Topic that is stickied explains about everything. Basically you are outputting the HTML to the browser before calling the header function. That is not allowed, either move the processing to before the include(html) portion or use a javascript redirect: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/thanks.php'; echo '<script type="text/javascript>window.location = \'' . $url . '\';</script>'; exit(); Quote Link to comment https://forums.phpfreaks.com/topic/132472-cannot-modify-header-information/#findComment-688742 Share on other sites More sharing options...
robsumner Posted November 12, 2008 Author Share Posted November 12, 2008 Thank you very much! I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/132472-cannot-modify-header-information/#findComment-688813 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.