Jump to content


Photo

Help with header sending


  • Please log in to reply
11 replies to this topic

#1 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 21 May 2006 - 08:21 AM

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.
$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;
}
}

}


#2 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 21 May 2006 - 08:40 AM

[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--]

#3 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 22 May 2006 - 01:18 AM

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).

#4 Crimpage

Crimpage
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts
  • LocationBrisbane, Australia

Posted 22 May 2006 - 01:32 AM

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?

#5 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 22 May 2006 - 01:45 AM

No, I don't have any includes.

Here is the resulting HTML code from the page that has errors.
<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 />
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]

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 01:59 AM

so uh.. what about that br tag up there?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 May 2006 - 02:14 AM

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.

#8 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 22 May 2006 - 02:21 AM

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:

<?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'])){
That is only the top of the code.

#9 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 24 May 2006 - 01:10 AM

So would anyone happen to know what my problem could be?

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 May 2006 - 01:47 AM

is that file being included into another file?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 24 May 2006 - 02:57 AM

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:

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>";
    
    }


#12 dabip

dabip
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 May 2006 - 02:23 AM

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! :)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users