cfgcjm Posted December 10, 2007 Share Posted December 10, 2007 I'm testing my log in script and it happens to not be working...big surprise...unfortunately i can't see why... Below is the code for all of my files. My login form is part of index.php, the script is login.php and mysql.php is the database login. I'm getting the following errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2 Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Digicon Media Group : Login</title> <style type="text/css" media="all"> <!-- @import url(http://www.digiconmediagroup.com/market.css); --> a:link {color:black;text-decoration:none;} a:visited {color:purple;text-decoration:none;} a:hover {color:#0066CC;text-decoration:underline;} a:active {color:#FF6600;text-decoration:underline;} .style1 { text-align: left; } </style> </head> <body> <div id="outer"> <form method="post" action="login.php"> <table style="width: 328px; height: 160px" cellspacing="0" cellpadding="0"> <tr> <td style="width: 147px; height: 53px"></td> <td style="width: 164px; height: 53px"></td> </tr> <tr> <td style="height: 35px; width: 147px" class="login">USERNAME:</td> <td style="height: 35px; width: 164px" class="style1"> <input name="username" type="text" style="width: 95px" /> </td> </tr> <tr> <td style="height: 35px; width: 147px" class="login">PASSWORD:</td> <td style="height: 35px; width: 164px" class="style1"> <input name="password" type="password" style="width: 95px" /> </td> </tr> <tr> <td style="height: 47px; width: 147px"></td> <td style="height: 47px; width: 164px" valign="top" class="style1"> <input name="Submit1" type="submit" value="submit" /> </td> </tr> </table> </form> </div> </body></html> login.php <?php session_start(); require ('mysql.php'); if (isset ($_POST['submit'])) { $username = $_POST['username']; $password = md5 ($_POST['password']); // See if the user exists $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) { $_SESSION['users_id'] = $row['users_id']; $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = TRUE; header("Location:yes.php"); exit; } else { // User does not exist header("location:no.php"); exit; } } else { // The query failed print 'Error:' . mysql_error(); // print the MySQL error } } ?> mysql.php <?php /* Connect To MySQL */ $host = 'localhost'; $dbuser = 'XXXXX'; // $dbpass = 'XXXXX'; // $dbname = 'digiconm_clientlogin'; // $connect = @mysql_connect ($host, $dbuser, $dbpass) or die ('Could not connect to MySQL!'); // attempt to connect $select_db = @mysql_select_db ($dbname) or die ('Could not select database!'); // attempt to select database ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 You can't have any output before you set your cookies. Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted December 10, 2007 Author Share Posted December 10, 2007 how do you do that? I've never done that before Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted December 10, 2007 Author Share Posted December 10, 2007 My apologies but this is the first time i'm using php so i have no clue what that means... I tried using the setcookie() function and reformatted it as best as i could understand the link above. but it didn't work. any help would be great. errors:  Warning: Cannot modify header information - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4 new login.php: <?php require ('mysql.php'); setcookie(digicon,"yes"); session_start(); if (isset ($_POST['submit'])) { $username = $_POST['username']; $password = md5 ($_POST['password']); $success=0; // See if the user exists $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); $success=1; } if ($num > 0) { $_SESSION['users_id'] = $row['users_id']; $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = TRUE; exit; } if ($success = 1){print 'Yes';exit;} if ($success = 0){print 'No';exit;} } ?> Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Have you got any blank lines above the <?php opening ? If so remove them. Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 Move session_start() to the top of the script, prior to calling setcookie(). Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 session_start(); needs to go above both your include and your setcookie Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted December 10, 2007 Author Share Posted December 10, 2007 I made those changes... still have these errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4 login.php <?php session_start(); require ('mysql.php'); setcookie(digicon,"yes"); if (isset ($_POST['submit'])) { $username = $_POST['username']; $password = md5 ($_POST['password']); $success=0; // See if the user exists $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); $success=1; } if ($num > 0) { $_SESSION['users_id'] = $row['users_id']; $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = TRUE; exit; } if ($success = 1){print 'Yes';exit;} if ($success = 0){print 'No';exit;} } ?> Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted December 10, 2007 Author Share Posted December 10, 2007 if this makes any difference the exact same login script works fine on another site of mine that is hosted on a different server Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 You running this on some free host that is pumping ads on top of your page? Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted December 10, 2007 Author Share Posted December 10, 2007 no. The site that works is hosted by 1and1 (and thats the original code that works) and this one that isn't working is hosted by hostmonster Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Try comment out everything below session_start() and look at the source of the page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.