I need some help on a stupid error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

I need some help on a stupid error

Post by Howey »

Sorry im a newbie when it comes to php and I keep coming up with this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/sensipet/www/www/login.php:46) in /home/sensipet/www/www/header.php on line 3
main reason why, is that I want to store some informatio from my database into a session variable but it wouldnt show up so I tried to echo it to make sure that I was doing it correctly and the variable appeared but so did that stupid error.
$query3 = "SELECT * FROM $table WHERE username='$Name2'";
$result3 = mysql_query($query3);
$row3 = mysql_fetch_array($result3, MYSQL_ASSOC);

$id = $row3['ID'];
$_SESSION['id'] = $id;

$user = $Name2;
$_SESSION['user'] = $user;

$_SESSION['sc'] = $row3['sc'];

echo $row3['sc'];
So im not sure if im doing it wrong or im just being slow :P.
Thanks
Howey
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

session_start() must be placed before any output happens by your script. For details see: http://www.devnetwork.net/forums/viewtopic.php?t=6521
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

Yes I have done that its in the header should I move it to the individual scripts instead?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

show us your script (the main one from which you include) :)
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

Code: Select all

<?php
session_register('auth');
include ("config.php");


if($_GET['action'] == 'login') {
$Name2 = $_REQUEST['Name'];
mysql_select_db($database);
if(!($link_id = mysql_connect(localhost, $db_user, $db_pass))) die(mysql_erorr()); 

mysql_select_db($database);

$sql = "SELECT ID FROM users WHERE username='$Name2' AND password='" . md5($_REQUEST['Password']) . "'"; 


$result = mysql_query($sql)
	or die ("failed at result");



$num = mysql_num_rows($result);


if ($num == 1)
{
$sql = "SELECT ID from users
	WHERE username='$Name2'
	AND Password=password('$Password')";

$auth="yes";



$query3 = "SELECT * FROM users WHERE username='$Name2'";
$result3 = mysql_query($query3);
$row3 = mysql_fetch_array($result3, MYSQL_ASSOC);

$id = $row3['ID']; 
 $_SESSION['id'] = $id; 

$user = $Name2; 
 $_SESSION['user'] = $user; 

$_SESSION['sc'] = $row3['sc'];

echo $row3['sc'];


$today = date("m.d; h:i.a");

$makelog = mysql_query("INSERT INTO `logs_login` ( `ID` , `username` , `IP` , `time` ) 
VALUES (
'$id', '$Name', '$REMOTE_ADDR', '$today'
)");

include("index.php");


die;

}


if ($num == 0) {

echo("<center>Username or Password was Incorrect<BR><BR><a href=index.php>Back</a>");

die;

} else {
echo ("<center>login failed<BR><BR><a href=index.php>Back</a>");
die;
}
include("footer.php"); }
else {

include ('header.php'); ?>

<table border=2>
<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>?action=login" method="post"> 

<tr><td>
Username:<br>
</td><td> 
<input type="text" name="Name" size="25">
</td></tr>

<tr><td>
Password:<br>
</td><td>
<input type="password" name="Password" size="30">
</td></tr>

<tr><td colspan=2>
<center><input type="submit" value="submit" name="submit"></center> 
</tr></td>
</form>
</table>
<?php
include ('footer.php'); }?>
?>
I believe that is what you wanted :P I hope to early to think lol

edit patrikG: added

Code: Select all

-tags.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

from php.net/session_register
php.net/session_register wrote: Caution

If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
Also:
php.net/session_register wrote:Caution

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.
User avatar
Howey
Forum Newbie
Posts: 17
Joined: Sun May 16, 2004 5:48 pm
Location: Middle of no where

Post by Howey »

Thank you everyone i believe it works now :P
Post Reply