MsRedImp Posted October 31, 2007 Share Posted October 31, 2007 Hi guys, I wanted to include a header in my login script so that when somebody registers a new user it directs them to a certain page. The registration is happening and the users are being added to the database, but this piece of error code appears on the page and it doesn't redirect to any page: Warning: Cannot modify header information - headers already sent by (output started at F:\wamp\www\euro\submitregister.php:13) in F:\wamp\www\euro\submitregister.php on line 111 Line 111 is where the header text is placed: if(mysql_affected_rows() > 0) { $_SESSION['login'] = $_POST['login']; header ("Location: registered.php"); } else { $login = "User name already exists."; } Thanks for your help. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 You have output on line 13 in submitregister.php and you are calling header() on line 111 in that file. You cannot have any output before you use header. What is on/around line 13 in submitregister.php? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 Fyi there is a sticky about header errors, please read that before posting header errors Quote Link to comment Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 What do you mean by output? Line 13 is where <title> begins: <title> <?php $title = "Registering..."; echo "$title"; ?> </title> Sorry about that, didn't see the sticky. Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 What do you mean by output? echo "$title"; Quote Link to comment Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 But I have echo outputs throughout my script, and want to use header during the form. Is there a way around this? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 31, 2007 Share Posted October 31, 2007 What do you mean by output? Line 13 is where <title> begins: <title> <?php $title = "Registering..."; echo "$title"; ?> </title> Sorry about that, didn't see the sticky. Well there is you problem. You are outputting text/html before you call the header function Output is considered anything passed back to the browser, this can be text, html, newlines spaces etc. PHP will output anything before and after the PHP tags (<?php ?>) or any function your use within PHP that returns output eg echo, print, print_r, sprint etc. You should do all processing before you output anything rather than do them both at the same time. If you dont want to change your script you can use output buffering as a dirty fix. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 Oxymoron at what you are saying. A header("location:"); changes your page location destroying all output, so why would you output before it. Any other header defines something, so how can you define an object after making it. Quote Link to comment Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 Because somebody told me this would be a good function to use to direct my users to a new page upon different register procedures. So do I have to put all of my html script inside the <php> tags? Is there any other way of directing a user to a certain page depending on what happens when they register? Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 You have two choices, put your PHP code up top or use <meta http-equiv="refresh" content="0; URL=yourpagehere.php"> Quote Link to comment Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 Thanks guys. Quote Link to comment 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.