Jump to content

getting back into php, simple code, not working!!


legohead6

Recommended Posts

I keep getting the stupid headers already sent, i went through the sticky, and ive tried a ton of things.. i cannot figure out why.

 

Index.php

<?PHP
include "header.php";

     echo "<h2>Welcome</h2>
      <p>Well, i decided that this space earns something better then a white page 
        with links to my other sites, soo here it is! Im not exactly sure how 
        this will turn out, i am also looking for input from others as to what 
        i should put here. Anything is possible!!";

include "footer.php";
?>

 

 

header.php

<?PHP
SESSION_START();
$connect=mysql_connect ("localhost", "*****", "********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("********"); 
if(empty($_SESSION['user'])){
if(isset($_POST['log'])){
$user2=$_POST['user'];
$pass2=$_POST['pass'];
$query2 = "SELECT * FROM Members WHERE username='$user2'";
$result2 = mysql_query($query2) or die ("Error in query: $query2. ".mysql_error());
$exist = mysql_num_rows($result2);
while($caa = mysql_fetch_row($result2)){
$pass1=$caa[2];
}
if($exist = 1){
if($pass1 == "$pass2"){
$_SESSION['user'] = "$user2";

}else{
$login= "<p align=center>Invalid Username/Password<br><form method=POST><table width=100><tr><td colspan=2><h2>Sign In</h2></td></tr><tr><td><b>Username:</b></td><td><input type=text name=user size=10></td></tr><tr><td><b>Password: </b></td><td><input type=password name=pass size=10></td></tr><tr><td><input type=submit name=log value=Login></form></td><td><a href=fpass.php>Forget Your Password?</a></td></tr></table>";
}//end of pass1
}else{
$login= "<p align=center>Invalid Username/Password<br><form method=POST><table><tr><td colspan=2><h2>Sign In</h2></td></tr><tr><td><b>Username:</b></td><td><input type=text name=user size=10></td></tr><tr><td><b>Password: </b></td><td><input type=password name=pass size=10></td></tr><tr><td><input type=submit name=log value=Login></form></td><td><a href=fpass.php>Forget Your Password?</a></td></tr></table>";
}//end of exist
}else{
$login= "<form method=POST><table width=100><tr><td colspan=2><h2>Sign In</h2></td></tr><tr><td><b>Username:</b></td><td><input type=text name=user size=10></td></tr><tr><td><b>Password: </b></td><td><input type=password name=pass size=10></td></tr><tr><td><input type=submit name=log value=Login></form></td><td><a href=fpass.php>Forget Your Password?</a></td></tr></table>";
}//end of if login button
}else{//if logged in
$user=$_SESSION['user'];
$login= "<p align=center>Welcome $user!</p>";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="#" />
<meta name="keywords" content="#" />
<meta name="author" content="#" />
<link rel="stylesheet" type="text/css" href="http://mattswebpage.com/beta/voodoo.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://mattswebpage.com/beta/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="http://mattswebpage.com/beta/handheld.css" media="handheld" />
<title>Mattswebpage.com</title>
</head>

<body>
<div class="top"></div>
<div class="page_wrap clearfix">
  
<div class="header"> 
  <div class="header_block"> 
    <div class="logo"><img alt="logo" src="http://mattswebpage.com/beta/img/pc_logo.jpg" /></div>
    <h1>Mattswebpage.com BETA</h1>
    What other website do you need? </div>
</div>
  
<div class="navbar" id="nav"> 
  <ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="about.php">About</a></li>
    <li><a href="#">Forum</a></li>
    <li><a href="#">Info</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</div>
  <div class="container clearfix">
    <div class="left_column">
      <h3>News</h3>
      <p>Nov 3. New Mattswebpage getting started. Visit beta.mattswebpage.com!</p>
    </div>
    <div class="center_column"> 
      
<div class="box_right">
<?
echo "$login"; ?>
</div>

Well, the main problem I see could be the fact the includes are NOT surrounding the file by  ().

 

what i mean is this, (Your code for example)

include("header.php");

     echo "<h2>Welcome</h2>
      <p>Well, i decided that this space earns something better then a white page
        with links to my other sites, soo here it is! Im not exactly sure how
        this will turn out, i am also looking for input from others as to what
        i should put here. Anything is possible!!";

include("footer.php");

Ummm from my point of view it seems like the problem is in header.php when you use Session_start();

 

See if this changes anything.

 

1. Take out session_start(); from header.php and move it to the VERY top (before <html>) on the index.

 

2. Add session_start(); to index.php. =)

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/matts15/public_html/beta/index.php:1) in /home/matts15/public_html/beta/header.php on line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/matts15/public_html/beta/index.php:1) in /home/matts15/public_html/beta/header.php on line 2

You need to place session_start(); in every page. If it fixed the error you are getting, then it would be easier to deal with to just put session_start(); in all the pages. (Pain in the butt, I know) but it would cause less problems.

wow, i just copied the exact code from the other page that works fine to the index, and it still does not work, this is really weird

 

exact same code on 2 pages, 1 works, the other doesnt

 

i put an '@' in front of Session start on the index and it works fine now, but who knows the real probelm

Well, the main problem I see could be the fact the includes are NOT surrounding the file by  ().

 

include is not a function and therefore does not require braces around its arguments.

 

The problem is somewhere before session_start() you have white space outside of the <?php ?> tags. We can't tell from here but you need to track it down and remove it.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.