Page 1 of 1
I need some help on a stupid error
Posted: Tue May 25, 2004 5:28 am
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

.
Thanks
Howey
Posted: Tue May 25, 2004 5:30 am
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
Posted: Tue May 25, 2004 5:55 am
by Howey
Yes I have done that its in the header should I move it to the individual scripts instead?
Posted: Tue May 25, 2004 5:58 am
by patrikG
show us your script (the main one from which you include)

Posted: Tue May 25, 2004 6:11 am
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

I hope to early to think lol
edit patrikG: added
Posted: Tue May 25, 2004 12:34 pm
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.
Posted: Wed May 26, 2004 6:34 am
by Howey
Thank you everyone i believe it works now
