...

View Full Version : Help with User System



SBDTHRU
02-25-2010, 12:53 AM
Trying to set up a portal for my user system. But when I use this


<?php
include("login.php");
?>

I get


Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/index.php:15) in /home/mysite/public_html/login.php on line 47

Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/index.php:15) in /home/mysite/public_html/login.php on line 48
Thank You! You will be redirected

Lines 47 & 48 of Login:

setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");

Entire login file

<?
oB_start();
// allows you to use cookies.
include("config.php");
if($logged[username] && $logged[banned] ==yes)
echo("<META HTTP-EQUIV=\"Refresh\"
CONTENT=\"0; URL=banned.php\">");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("<font color='white'>
<link rel='stylesheet' type='text/css' href='style-2.css' media='screen,projection'>
<center><form method=\"POST\">
<table>
<tr>
<td align=\"right\">
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"right\">
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</td></tr><tr></font>
<td align=\"center\">
<a href=\"register.php\" target='1'>Register Here</a>
</td></tr></table></form></center>");
}
if ($_POST[login]) {
// the form has been submitted. We continue...
$username=$_POST['username'];
$password = md5($_POST[password]);
// the above lines set variables with the submitted information.
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data[password] != $password) {
// the password was not the user's password!
echo "Incorrect username or password!";
}else{
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
// the above lines set 2 cookies. 1 with the user's id and another with his/her password.
echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=../~sbdthru/index.php\"/>Thank You! You will be redirected");
// modify the above line...add in your site url instead of yoursite.com
}
}
}
else
{
// we now display the user controls.
$new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'");
$new = mysql_num_rows($new);
echo ("
<link rel='stylesheet' type='text/css' href='style-2.css' media='screen,projection'>
<center>Welcome <b>$logged[username]</b><br /></center>
- <a href=\"editprofile.php\" target='1'>Edit Profile</a><br />
- <a href=\"messages.php\" target='1'>Private Messages ($new New)</a><br />
- <a href='contact.php' target='1'>Contact Admin</a><br />
- <a href=\"logout.php\" target='1'>Logout</a><br>
</font></body>");
if($logged[level] == Admin)
{
echo("
- <a href='admincp.php' target='1'>Admin</a><br>
- <a href=\"members.php\" target='1'>Member List</a><br />");
}
}
?>

masterofollies
02-25-2010, 01:00 AM
I can't remember what fixes this, but it means your sending the same information twice, usually cookies is the problem on my website that causes this. Or else it's my session_start's

SBDTHRU
02-25-2010, 01:09 AM
I can't remember what fixes this, but it means your sending the same information twice, usually cookies is the problem on my website that causes this. Or else it's my session_start's

Figured that was the problem too, I just couldn't find out what exactly was causing it.

MattF
02-25-2010, 01:25 AM
Unless it's a custom function, you've misspelt oB_start and disabled your output buffering. Lowercase it: ob_start();

Courtney
02-25-2010, 02:01 AM
Make sure you get rid of any whitespace. Extra spaces, unneeded empty lines can all cause the error.

Looks like the code you pasted has a extra space before include("login.php");

SBDTHRU
02-25-2010, 02:32 AM
I changed the oB_start(); and tried to find any whitespace. Still have the same problem. :confused:

MattF
02-25-2010, 02:50 AM
You need to put that function at the top of whichever files sends the initial headers then. You're getting that error because body content has already been transmitted to the browser when you try setting the cookies. Buffer all of the output and you'll be fine.

Courtney
02-25-2010, 02:55 AM
Yep I agree with MattF. Relooking at it you are sending html (echo) before the header info. The header needs to be before any html or anything else is sent to be displayed.

SBDTHRU
02-25-2010, 03:19 AM
You need to put that function at the top of whichever files sends the initial headers then. You're getting that error because body content has already been transmitted to the browser when you try setting the cookies. Buffer all of the output and you'll be fine.

Could you n00bify this? I'm still learning. :rolleyes:

I'm assuming you mean

setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");

MattF
02-25-2010, 03:31 AM
Remove the ob_start(); line from login.php and put that ob_start(); line just after the opening php tag in the index.php file.

SBDTHRU
02-25-2010, 03:41 AM
Remove the ob_start(); line from login.php and put that ob_start(); line just after the opening php tag in the index.php file.

Nope, :confused: same error.

MattF
02-25-2010, 03:58 AM
Post your index.php.

SBDTHRU
02-25-2010, 04:02 AM
Post your index.php.

Login and everything works fine, if I just use login.php it redirects to the index and I can go as usual.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>StakeBeast&trade;</title>

<link rel="stylesheet" type="text/css" href="style.css" media="screen,projection">
</head>
<body>

<div id="container" class="clearfix">

<h1><em></em></h1>

<h2></h2>

<div id="content">
<iframe src ="../~sbdthru/content.php" width="515px" height="100%" id="1">
<p>Your browser does not support iframes.</p>
</iframe>


</div>
<div id="nav"><?php
ob_start();
include("login.php");
?>
</div>
</div>

<address>
&copy; 2008 All Rights Reserved.
</address>

</body>
</html>

MattF
02-25-2010, 04:12 AM
<?php
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>StakeBeast&trade;</title>

<link rel="stylesheet" type="text/css" href="style.css" media="screen,projection">
</head>
<body>

<div id="container" class="clearfix">

<h1><em></em></h1>

<h2></h2>

<div id="content">
<iframe src ="../~sbdthru/content.php" width="515px" height="100%" id="1">
<p>Your browser does not support iframes.</p>
</iframe>


</div>
<div id="nav">
<?php
include("login.php");
?>
</div>
</div>

<address>
&copy; 2008 All Rights Reserved.
</address>

</body>
</html>
<?php
ob_end_clean();
exit(ob_get_contents());
?>

kbluhm
02-25-2010, 04:12 AM
You cannot set cookies after output has begun. Place ob_start() before ANYTHING has been sent to the client.

And function names are case-insensitive. ;)

SBDTHRU
02-25-2010, 04:13 AM
<?php
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>StakeBeast&trade;</title>

<link rel="stylesheet" type="text/css" href="style.css" media="screen,projection">
</head>
<body>

<div id="container" class="clearfix">

<h1><em></em></h1>

<h2></h2>

<div id="content">
<iframe src ="../~sbdthru/content.php" width="515px" height="100%" id="1">
<p>Your browser does not support iframes.</p>
</iframe>


</div>
<div id="nav"><?php
include("login.php");
?>
</div>
</div>

<address>
&copy; 2008 All Rights Reserved.
</address>

</body>
</html>

Like this?

EDIT: That worked. :D Thanks for all your help guys.

MattF
02-25-2010, 04:16 AM
And function names are case-insensitive. ;)

I always thought they were case sensitive. Never tested the theory, obviously, :D but just assumed. Cheers for the pointer.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum