Old 11-13-2007   #1 (permalink)
Registered User
 
Join Date: Nov 2007
Posts: 5

Question PHP Output Warnings in Membership System

My system seem to be working fine and i followed the tutorial all the way through! But whenever there is a "session_start" on a page I get this warning when I test the page using wamp 5. The page shows as I want but there is a warning at the top.

Can Anyone help?

Login.php

Here is the warning produced on the login.php page

"Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\wamp\www\K2F1\Pages\login.php:6) in C:\Program Files\wamp\www\K2F1\Pages\login.php on line 485

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\wamp\www\K2F1\Pages\login.php:6) in C:\Program Files\wamp\www\K2F1\Pages\login.php on line 485"

Here's the code
Code:
<table width="555" height="300" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>
			<?php
			session_start();
			include 'config.php';
			
			if(isset($_POST['login']))
			{
			
			$username = trim(addslashes($_POST['username']));
			$password = md5(trim($_POST['password']));
			
			$query = mysql_query("SELECT * FROM Users WHERE Username = '$username' AND Password = '$password' LIMIT 1") or die(mysql_error());
			
			$row = mysql_fetch_array($query);
			
			//now check see if they are activated
			
			if(mysql_num_rows($query) > 0)
			{
			
			if($row['Activated'] > 0)
			{
			
			$_SESSION['s_logged_n'] = 'true';
			$_SESSION['s_username'] = $username;
			$_SESSION['s_name'] = $row['Name'];
			
			header("Location: member.php");
			
			} else {
			
						
			echo'
			<html>
			<head>
			<title>K2F1 - The Revolution Has Come - Member Login</title>
			<link href="style.css" rel="stylesheet" type="text/css">
			
			</head>
			
			<body>
			<div id="error">
			<p>Sorry, you must activate your K2F1 account before you can access the member area. Please check your email and try again. Don'."'".'t forget to check your email spam/junk folder.</p>
			<p>Didn'."'".'t recieve your validation email? <a href="resend.php">Click here</a> to resend your validation email.</p>
			
			</div>
			</body>
			</html>
			';
			
			}
			
			} else {
			
			echo'
			<html>
			<head>
			<title>K2F1 - The Revolution Has Come - Member Login</title>
			<link href="style.css" rel="stylesheet" type="text/css">
			
			</head>
			
			<body>
			<div id="error">
			<p>Sorry, there was an error while processing your login. It appears that your Username and/or Password were incorrect. Please try again.</p>
			<p>Didn'."'".'t recieve your validation email? <a href="resend.php">Click here</a> to resend your validation email.</p>
			
			</div>
			</body>
			</html>
			';
			
			}
			
			} else {
			
			?>
			<link href="style.css" rel="stylesheet" type="text/css">
			<body>
			
			<div id="wrapper">
			<p><span class="style6">K2F1 Member Login</span><br>
			    <div id="main">
			  </p>
			<p><strong>You must login to K2F1 to view this page. Enter your Username and Password and then click the login button.</strong></p>
			<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
			<p><span class="style12">Username:</span><br>
			<input name="password" type="text" Cid="username">
			<p><span class="style12">Password:</span><br>
			<input name="password" type="password" id="password">
			</p>
			<p>
			<input name="login" type="submit" id="submit" Value="Login">
			</p>
			</form>
			<p><strong>Didn't recieve your validation email? <a href="resend.php" class="style8">Click here</a> to resend your validation email.</strong></p>
			<p><strong>Need a K2F1 member account? <a href="register.php" class="style9">Click here</a> to register. <span class="style10">It's completely free!</span></strong></p>
		
		    <?php } mysql_close($l); ?>	
					</td>
          </tr>
          <tr>
            <td height="1000">&nbsp;</td>
          </tr>
        </table>
Tash-n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-13-2007   #2 (permalink)
Registered User
 
Join Date: Nov 2007
Posts: 5

Question Logout.php

Here is the Warning produced by the logout.php page

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\wamp\www\K2F1\Pages\logout.php:6) in C:\Program Files\wamp\www\K2F1\Pages\logout.php on line 477

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\wamp\www\K2F1\Pages\logout.php:6) in C:\Program Files\wamp\www\K2F1\Pages\logout.php on line 477

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\wamp\www\K2F1\Pages\logout.php:6) in C:\Program Files\wamp\www\K2F1\Pages\logout.php on line 487


Here is the code

Code:
<table width="555" height="300" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>
			<?php

session_start();


$_SESSION['s_logged_n'] = '';
$_SESSION['s_name'] = '';
$_SESSION['s_username'] = '';

session_destroy();


header("Location: login.php");

?>			</td>
          </tr>
          <tr>
            <td height="1000">&nbsp;</td>
          </tr>
        </table>
Tash-n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-13-2007   #3 (permalink)
Registered User
 
Join Date: Nov 2007
Posts: 5

Question Finally The member.php

Here is the warning produced from the member.php page

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\wamp\www\K2F1\Pages\member.php:6) in C:\Program Files\wamp\www\K2F1\Pages\member.php on line 475

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\wamp\www\K2F1\Pages\member.php:6) in C:\Program Files\wamp\www\K2F1\Pages\member.php on line 475

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\wamp\www\K2F1\Pages\member.php:6) in C:\Program Files\wamp\www\K2F1\Pages\member.php on line 545

Here is the code

Code:
<table width="555" height="300" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><?php
			session_start();
			if($_SESSION['s_logged_n'] == 'true'){
			include 'process.php';	
			?>
              <p class="style6">K2F1 Members Area</p>
              <p>
                <?php include 'menus.php' ?>

                <body>
                
                <div id="wrapper">
              </p>
              <p>
                <?php
			
			switch($_GET['change']){
			
			case 'password':
		
			echo '<form action="'.$_SERVER['PHP SELF'].'" method="post">
			<p>Current Password:<br>
			<input name="current" type="password"></p>
			<p>New password:<br>
            <input name="new" type="password"></p>
			<p>Confirm new password:<br>
			<input name="confirm" type="password"></p>
			<p><input type="submit" value="Change Password" name="changepassword"></p>
			</form>
			';
			
			break;
			
			case 'email':

echo '<p>
WARNING! - By changing your email address you will have to re-validate your K2F1 member account. Make sure you email address is 100% correct.</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current email:<br>
<input name="current" type="text"></p>
<p>New email:<br>
<input name="new" type="text"></p>
<p>Confirm new email:<br>
<input name="confirm" type="text"></p>
<p><input type="submit" value="Change Email" name="changeemail"></p>
</form>
';

break;

case 'account':

echo '<p>
WARNING - By closing your account, you will not be able to login to K2F1 again using these account details. Press the button below to confirm you wish to close your account</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p><input type="submit" value="Close Account" name="closeaccount"></p>
</form>
';

break;

default:

echo '<p>Welcome to the K2F1 Members Personal Area!</p>';

}

?>
                  </p>
            <?php
} else {
header("Location: login.php");
}
?></td>
          </tr>
          <tr>
            <td height="1000">&nbsp;</td>
          </tr>
        </table>
Tash-n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-13-2007   #4 (permalink)
Registered User
 
Join Date: Aug 2004
Posts: 110

PHP Code:
<?php session_start(); ?>
MUST be the FIRST line of code in ALL pages.
Jolt is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-13-2007   #5 (permalink)
Registered User
 
Join Date: Nov 2007
Posts: 5

Question

so should I remove the session_start at the begining?
Tash-n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2007   #6 (permalink)
PHP Lover
 
Join Date: May 2007
Location: Zug, Switzerland
Posts: 89

Quote:
Originally Posted by Tash-n View Post
so should I remove the session_start at the begining?
The session_start function must go at the very very top of your code. Before even the <html> tag.
__________________
You can call me Greg
Gjbphp is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2007   #7 (permalink)
Rusty Bio-Hazard!
 
notjustgraphics's Avatar
 
Join Date: Sep 2006
Location: Toronto, Ontario, Canada
Posts: 1,160

Send a message via MSN to notjustgraphics
Quote:
Originally Posted by Gjbphp View Post
The session_start function must go at the very very top of your code. Before even the <html> tag.
Yup... what he said!

Mike.

Sorry.. feel like we cover this exact issue every couple of months. It's a common problem non-experienced PHP developers run into... it's almost comical now.
__________________
notjustgraphics is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2007   #8 (permalink)
Janitor of Lunacy
 
tamlin's Avatar
 
Join Date: May 2006
Location: Sitting in the Wishing Chair
Posts: 5,124

Quote:
Originally Posted by notjustgraphics View Post
Sorry.. feel like we cover this exact issue every couple of months. It's a common problem non-experienced PHP developers run into... it's almost comical now.
I know what you mean - I don't use PHP and even I recognise that error now! Maybe we need a wiki entry for this one?
__________________


Religion: It's all fun and games until someone gets burned at the stake...
tamlin is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-15-2007   #9 (permalink)
Registered User
 
Join Date: Nov 2007
Posts: 5

Thanks guys. Help much appriciated!
Tash-n is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ: A Complete Membership System scrowler BioRUST Specific Threads 13 01-18-2007 11:16 PM
A Complete Membership System Tones HTML / PHP / ASP / JS 0 01-14-2007 02:42 PM
PERL - extracting output of ifconfig to get local system IP address... thecubed HTML / PHP / ASP / JS 3 08-14-2006 12:35 AM
RE: A Complete Membership System ThEMakeR HTML / PHP / ASP / JS 0 07-18-2006 12:59 PM
Help needed with PHP: Pagination in a tut system nitr0x HTML / PHP / ASP / JS 3 05-24-2005 05:30 PM


All times are GMT +1. The time now is 09:44 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT