Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: Cannot modify header information - headers already sent by (o

Status
Not open for further replies.

newbee22

Programmer
Jul 25, 2004
7
US
Hi !
I am tryinf to run the sample from the book linux.mysql,apache..and i keep geetign these errors..



errors :
Warning: Cannot modify header information - headers already sent by (output started at /home/kaiser/public_html/PHP/REGISTER/useraccess.php:8) in /home/kaiser/public_html/PHP/REGISTER/useraccess.php on line 31

Warning: Cannot modify header information - headers already sent by (output started at /home/kaiser/public_html/PHP/REGISTER/useraccess.php:8) in /home/kaiser/public_html/PHP/REGISTER/useraccess.php on line 32

Thanks in advance

and here is the actual code itself:


<?
// Filename : useraccess.php
// This file check for user login information
// Also, it check the user select theme for the PAGE


function checkAccess() {
echo " <br>inside checkAccess<br> ";
// First chekc for a POST
$email =$_POST['email'];
$password = $_POST['password'];
$remember = $_POST['remember'];

echo " Email $email <br>";
echo " pwd $password <br>";
//If no POST check fro cookie
if($email == NULL) {
echo " error inside if <br>";
$email = $_COOKIE['dummyemail'];
$password =$_COOKIE['dummypassword'];
echo " Email $email <br>";
echo " pwd $password <br>";

}
elseif (!$remember) {

//If there was a POST , save the cookie
// This will wipe out any lojn-term
// cookies by this same time.
echo " error inside elseif <br>";
setcookie('dummyemail',$email);
setcookie('dummypassword',$password);
echo " Email $email <br>";
//echo " pwd $password <br>";

}

$okay = false;
if ($email && $password) {
echo " inside if by mysql connect<br>";
mysql_connect("localhost","user","pass") or die ("Coudln't connect to server");
$sql ="select loginID,password,themeID FROM phpbase.login WHERE email='$email'";
$result = mysql_query($sql) or die("Coudln't query");

if($result) {
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);
$pass = $row['password'];
$userid = $row['loginID'];
$theme = $row['themeID'];

echo "<br>row : $row <br>";
echo "<br>pass : $pass <br>";
echo "<br>userid : $userid<br>";
echo "<br>theme : $theme <br>";

$passcrypt = crypt($password,substr($pass,0,12));
if($pass ==$passcrypt) {
$okay =true;
}
}
}
mysql_close();
}

if(!$okay) {
header("location: loginfailed.html");
}

if($remember) {
//remeber until may17 2033
// lon term cookie
setcookie('dummyemail',$email,2000000000);
setcookie('dummypassword',$password,2000000000);
}
return $theme;
echo "<br> <br>";
echo "<br> End of checkAccess<br>";
}//End_of_checkAccess()



function signup($email, $password, $themeID) {
echo " <br>inside signup<br> ";
mysql_connect("localhost","user","pass") or die ("Couldn't Connect to server");
$passcrypt = crypt($password);
echo " <br>INSIDE signup<br> ";
echo "pass : $passcrypt ";
$now = date("Y-m-d");
echo "now : $now<br> ";
echo "email :$email<br> ";
echo "password : $password<br> ";
echo "themeID : $themeID<br> ";
$insert_sql = " INSERT INTO phpbase.login(email, password, lastaccess, signup,themeID)
VALUES ('$email','$passcrypt','$now', '$now','$themeID')";
echo "<br> insert_sql : $insert_sql<br> ";
$result = mysql_query($insert_sql) or die ("Couldn't Insert into Table");

echo " <br>Exiting signup<br> ";
mysql_close();
return $result;

} // End_Of_signup




class ThemeInfo {
var $bgcolor;
}



function getTheme ($themeID) {
mysql_connect("localhost","user","pass") or die ("Couldn't connect to server");
$newtheme = new ThemeInfo;
$newtheme->bgcolor = "FFFFFF"; //white bg

$sql = "select backgroundcolor from phpbase.usertheme where themeID= '$themeID'";


$result = mysql_query($sql);
if ($result) {
if(mysql_num_rows($result) > 0 ) {
$row =mysql_fetch_array($result);
$newtheme->bgcolor = $row['backgroundcolor'];
}
}
mysql_close();
return $newtheme ;

} //End_Of_getTheme


function GetThemeNames() {
mysql_connect("localhost","user","pass") or die ("Couldn't connect to server");
$result = mysql_query("select * from phpbase.usertheme");
if($result) {
if(mysql_num_rows($result)> 0 ) {
while ($row = mysql_fetch_array($result)) {
$name = $row["name"];
$num = $row["themeID"];
$themeByNum[$num] = $name;
}
}
mysql_free_result($result);
}
mysql_close();
return $themeByNum;
} // EndOfGetThemeNames




function GeneratePassword() {
$wordList = array("apple","banana","bold","cook","catalog","animal","jump",
"tophat","wipe","wane","vanish","making","england","video","heavy","upside","keep"
,"merry","icecream","funny","flag","flower");
$firstword = $wordlist[rand(0,count($wordList) -1)];
$secondword = $wordlist[rand(0,count($wordList) -1)];
$number =rand(10,99);
$newpass = $firstword.$number.$secondword;

return $newpass;
}

?>
 
newbee:

The reason you're getting this error is because you're using a call to a header function after you've printed (echoed) text to the html.

When using a header function, it is a php requirement to utilize it before any html is displayed.

To avoid this problem, what I usually do is, rather than echo lines of html, I store the html in a variable. Then, I do the test if(condition) then print html else header.

This way, you avoid printing out html, and the header function will be valid.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Thanks cLFlaVA .:)

What I did was take out the echo statements as u suggested from the code and it worked fine ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top