legohead6 Posted November 6, 2008 Share Posted November 6, 2008 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> Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/ Share on other sites More sharing options...
Twister1004 Posted November 6, 2008 Share Posted November 6, 2008 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"); Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683302 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 fixed that, problem still exists check it at http://beta.mattswebpage.com Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683303 Share on other sites More sharing options...
Twister1004 Posted November 6, 2008 Share Posted November 6, 2008 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. =) Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683307 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 I have tried moving it, putting it on both pages, etc its not working Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683309 Share on other sites More sharing options...
Twister1004 Posted November 6, 2008 Share Posted November 6, 2008 Add this to the top of the pages, error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683310 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 Nothing changes with that, funny thing is it is only in the index, i went to one of my other pages(that also includes the header) and it works fine! Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683312 Share on other sites More sharing options...
ballhogjoni Posted November 6, 2008 Share Posted November 6, 2008 tell us which line of code you are getting the headers sent error and post the line of code here Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683314 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 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 Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683319 Share on other sites More sharing options...
Twister1004 Posted November 6, 2008 Share Posted November 6, 2008 Take out the session_start(); in header.php and place it in the index file. Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683322 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 tried that. when i remove session start it works, but as soon as i click to another page i loose the session Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683326 Share on other sites More sharing options...
Twister1004 Posted November 6, 2008 Share Posted November 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683327 Share on other sites More sharing options...
ballhogjoni Posted November 6, 2008 Share Posted November 6, 2008 tried that. when i remove session start it works, but as soon as i click to another page i loose the session make to include the session_start(); method at the top of every file, but not in the included files before any other code Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683329 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 did that, works great on everypage but the index.. Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683333 Share on other sites More sharing options...
legohead6 Posted November 6, 2008 Author Share Posted November 6, 2008 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 Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683334 Share on other sites More sharing options...
trq Posted November 6, 2008 Share Posted November 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683339 Share on other sites More sharing options...
Prismatic Posted November 6, 2008 Share Posted November 6, 2008 @ just suppresses errors generated by a function. The problem is still there Link to comment https://forums.phpfreaks.com/topic/131559-getting-back-into-php-simple-code-not-working/#findComment-683414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.