Jump to content

[SOLVED] PHP Header Problem


MsRedImp

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.