Jump to content

Archived

This topic is now archived and is closed to further replies.

dabip

Help with header sending

Recommended Posts

Hello, I have searched, and searched, I have found sites that are supposed to help, but they don't. I have two forms of SQL - PHP working. One on my computer, and another on an outer computer web server (free hosting). I develop on my computer (to save bandwidth) and then put it on the server and quickly test it. Well, I'm making a forum, and everything seems to work really well on my computer. When I put it on the server, I had a few header problems. I read about tweaking php system files, but since its not my server, I can't.


Error I get:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 40

Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 41
You've been logged in! Click Here to go Back
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 58

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 58

Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in /home/vhosts/dabgames.3000mb.com/forum/in.php on line 59
[/quote]

All code on the error page, everything is going through (so I know, such as the $_POST items) it just seems to be the header.
[code]
$username = "user10342";
$password = "(Its a secret :) )";
$hostname = "localhost";    
$dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
$selected = mysql_select_db("12141",$dbh)
    or die("Could not select dab");
    $once = 0;
if (isset($_COOKIE['in'])){
    ob_start();
    setcookie("in", "", time()-36000);
    setcookie("upass", "", time()-36000);
    setcookie("id", "",  time()-36000);
    
    ob_end_flush();
    
    echo "You've been logged Out. <a href=index.php> Click Here to go Back</a>";
        //header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header
        //header("Location: index.php"); // Jump to the link

} else {
if (isset($_POST['name']) && isset($_POST['pass']))
{
  $user=$_POST['name'];
  $pass=$_POST['pass'];
  $user=mysql_real_escape_string($user);
  $pass=mysql_real_escape_string($pass);

  $sql22 = "select login, password, id from users where login='$user' and password='$pass'";
  $result22=mysql_query($sql22);

  if (mysql_num_rows($result22) > 0)
  {
      
      ob_start();
      setcookie("in", $user, time()+36000);
    setcookie("upass", $pass, time()+36000);
    header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header
    header("Location: index.php"); // Jump to the link
    ob_end_flush();
     echo("You've been logged in! <a href=index.php> Click Here to go Back</a>");

    
  }
  else
  {
    echo("Whoops!  Wrong user name or password!<a href='index.php'> Click Here to Make an account</a>");
  }
}
$once =0;


$result2 = mysql_query("SELECT name, password, id FROM users where name = '$user' and password = '$pass' ");
while ($row = mysql_fetch_array($result2)) {
    if ($once == 0){
    session_start();
    setcookie("id", $row['id'], time()+36000);
    $once = 1;
    break;
}
}

}[/code]

Share this post


Link to post
Share on other sites
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=63200\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=63200[/a]

Many people have the same problem. Try to search the forum before posting a question that has been answered extensively.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

Share this post


Link to post
Share on other sites
Well, I checked out the link, and I read what it had to say about header sending. I don't see my problem, as I'm not sending any HTML at all. No echoing, nothing. The code you saw was all that was saved on the file. (besides the <?php tags).

Share this post


Link to post
Share on other sites
View the source of the page when you get these errors and post the top say, 30 lines here.

That should show you what has been sent already.

Also have you got and include()'s that might be putting something to screen?

Share this post


Link to post
Share on other sites
No, I don't have any includes.

Here is the resulting HTML code from the page that has errors.
[code]<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>38</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>39</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>40</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>41</b><br />
You've been logged in! <a href=index.php> Click Here to go Back</a><br />
<b>Warning</b>:  session_start(): Cannot send session cookie - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>58</b><br />
<br />
<b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>58</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/vhosts/dabgames.3000mb.com/forum/in.php:1) in <b>/home/vhosts/dabgames.3000mb.com/forum/in.php</b> on line <b>59</b><br />
[/code]
Here is the URL to the file-ish. Just type in admin for the username then guest for the password (all lowercase). Then you will get the error page right when you hit login.
[a href=\"http://dabgames.3000mb.com/forum/\" target=\"_blank\"]http://dabgames.3000mb.com/forum/[/a]

Share this post


Link to post
Share on other sites
That <br /> tag is part of the error output, however, there does seem to be some whitespace. make sure there is nothing (no whitespace) before your <?php tags.

Share this post


Link to post
Share on other sites
That space was from the forum. It's not really there on the code. And there isn't any spaces on the top <?php either. Code of the top:

[code]<?php
$username = "user10342";
$password = " Secret ";
$hostname = "localhost";    
$dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
$selected = mysql_select_db("12141",$dbh)
    or die("Could not select dab");
    $once = 0;

if (isset($_COOKIE['in'])){
[/code]
That is only the top of the code.

Share this post


Link to post
Share on other sites
So would anyone happen to know what my problem could be?

Share this post


Link to post
Share on other sites
No. I'm going to it from a form.
So, on index, I have a form that asks for the username and password, and when you hit login, I get the data through the $_POST command.

It seems the problems are only the cookie and the head( commands.

So,
setcookie("in", "", time()-36000);
setcookie("upass", "", time()-36000);
setcookie("id", "", time()-36000);
and
setcookie("in", $user, time()+36000);
setcookie("upass", $pass, time()+36000);
header('HTTP/1.1 301 Moved Permanently'); // Clean 301 header
header("Location: index.php"); // Jump to the link

are the problemed code.

Here is the Index login code:

[code]
echo "You are not logged in!<br /><form method='POST' action='in.php'>
    <p>Name&nbsp; :&nbsp; <input type='text' rows='1' name='name' cols='20' size='52'><br>
    Passqord&nbsp;&nbsp; :&nbsp; <input type='password' name='pass' size='52'><br>
    <p><input type='submit' value='Log In' name='B1'></p></form>";
    
    }
[/code]

Share this post


Link to post
Share on other sites
Well, some how I got it.

I (searched for the error and found/)read:
[a href=\"http://www.webmasterworld.com/forum88/1100.htm\" target=\"_blank\"]http://www.webmasterworld.com/forum88/1100.htm[/a]

And tried what the guy on the last post did. And it worked for me too. I think that mabye my cache or something had a bit of the old code too. So, deleting the old one, creating a new text file, might of triggered a complete file refresh or something. I'm not sure. But it works perfect now. Thanks everyone for the help! :)

Share this post


Link to post
Share on other sites

×

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.