Hey folks,
A quick question regarding headers and stuff...
I'm getting the following error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/i_betcha_wanna_know/public_html/index.php:5) in /home/i_betcha_wanna_know/public_html/phpfunctions/sitewidefunctions.php on line 3
I read a lot of articles online about this error, and found a couple closed topics about it here on phpfreaks - but these topics do not suffice to answer my questions.
My code is below... I've echoed out the first 10 lines or so rather than straight HTML because I read somewhere online that the first thing that should always appear in your .php pages is a <?php tag, and it should always end it with a ?>, with no white space above or below. I can recall getting other errors if this was not the case.
After reading several other resources online, it appears that I must somehow call the session information before anything is sent to the browser.
Do echoes count as something sent to the browser?
This code works perfectly on my localhost WAMPserver, when I upload it to my web host however, I start getting all these retarded errors.
How could I possibly extract the session information out of this log in page - it's embedded deep down in a few if statements, for loops, etc.
session_start() is located at the very top of the sitewidefunctions.php function library I have created.
The sitewidefunctions.php page is referenced in all pages that will either need sessions, or any other complex functions that specific page would need.
For example, getmainlinksfade(), as shown below is located in this library.
<?php
echo "
<html>
<head>
<title>TITLE</title>
<link rel='stylesheet' type='text/css' href='CSS/global.css'/>
<script type='text/javascript' src='JS/util-functions.js'></script>
<script type='text/javascript' src='JS/clear-default-text.js'></script>
</head>
<body>
<div id='wrap'>
<div id='content'>
<div class='maintitle'>TITLE</div>";
error_reporting(E_ALL & ~E_NOTICE);
include "phpfunctions/sitewidefunctions.php";
include "phpfunctions/uniquevisitorcounter.php";
if(loggedin())
{
header("Location: home.php");
exit();
}
getmainlinksfade();
getsubtitlefade('Books');
getbooksfade('copyright');
$username = $_POST['username'];
$password = $_POST['password'];
$rememberme = $_POST['rememberme'];
if($username&&$password)
{
$qry = mysql_query("SELECT * FROM users WHERE username='$username'");
if(mysql_num_rows($qry)==0) echo "<div id='index_errorlogin'> No user found <br/></div>";
else
{
while($row = mysql_fetch_assoc($qry))
{
$db_password = $row['password'];
if(md5($password)==$db_password)
{
$loginok=TRUE;
mysql_query("UPDATE users SET isOnline=1 WHERE username='$username'");
}
else
{
$loginok=FALSE;
echo "<div id='index_errorlogin'>$username found! - Incorrect password <br/></div>";
break;
}
if($loginok==TRUE)
{
if($rememberme=='on')
{
setcookie("username", $username, time() + 7200);
$_SESSION['username']=$username;
}
else $_SESSION['username']=$username;
header("Location: home.php");
exit();
}
else die("");
}
}
}
else echo "<div id='index_errorlogin'>To view the entire library - Please log into the system below<br/></div>";
echo"
<div id='index_form'>
<form action='index.php' method='post'>
<input type='text' name='username' value='username' class='cleardefault'><br/>
<input type='password' name='password' class='cleardefault'><br/>
<input type='checkbox' name='rememberme'><span id='index_rememberme'>Remember Me</span>
<input type='submit' name='login' value='Login' id='index_login'>
</form>
</div>
<br/><br/>";
getindexstats();
getfooter();
echo"
</div>
</div>
</body>
</html>";
?>
Can someone point me in the right direction?
Alex from PHPAcademy uses this log-in technique - I watched his videos on Youtube and embedded his logic into my page.
Again, this works perfectly on my WAMP!
I know my question is kind of vague but any help is appreciated.
Thanks and Cheers!
rxgvhqkrywq6cxdjoar