Page 1 of 1

Login page error

Posted: Tue Jan 20, 2009 1:02 am
by Greg19
hello everyone, I'm having a bit of a problem with a php login script. I'm getting these errors:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/J/a/p/JapII/html/reftek/site/support.php:1) in /home/content/J/a/p/JapII/html/reftek/site/support.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/J/a/p/JapII/html/reftek/site/support.php:1) in /home/content/J/a/p/JapII/html/reftek/site/support.php on line 2
I can still login, however the user will not be automatically redirected to the next page.
Here is the php I'm using:

Code: Select all

<?php
  session_start(); 
$query = mysql_connect("*******", "******", "******") or die(mysql_error());
mysql_select_db('*******', $query) or die(mysql_error());
  
 if(isset($_GET['try'])) {
  
     If(empty($_POST['company']) OR empty($_POST['password'])) {
         echo 'Please fill in all required fields.';
     }
     else {
        $company = addslashes($_POST['company']);
        $password = md5($_POST['password']);
        $query = mysql_query("SELECT usergroup FROM users WHERE company = '" . $company . "' AND password = '" . $password . "'") or die(mysql_error());
         
        
         list($usergroup) = mysql_fetch_row($query);
  
         if(empty($usergroup)) {
            echo 'No combination of username and password found.';
         }
         else{
             session_start();
             $_SESSION['company'] = ($_POST['company']);
             header('Location: account.php'); die ("<a href='account.php'> Next>> </a>\n");
        }      
    
     }
  
 }
 
 if (isset($_POST['guest'])){
     session_start();
     $_SESSION['company'] = ($_POST['guest']);
     header('Location: account.php'); die ("<a href='account.php'> Next>> </a>\n");
     }
?>
and the form:

Code: Select all

<form action="support.php?try=true" method="post" class="user_login">
       Username: <br/> 
       <input type="text" name="company"><br/>
     Password:<br/>
       <input type="password" name="password"><br>
       <br>
       <input type="submit" value="Login">
     </form>
 
     <form action="support.php" method="post" class="guest_login" >
     Login as a guest:
     <div style="display:none;"><input type="text" name="guest" value="guest"></div>
    <input type="submit" value="guest">
   </form>
Thanks for any help.

Re: Login page error

Posted: Tue Jan 20, 2009 1:36 am
by requinix
Make sure there's no spaces or newlines before the <?php tag.
Also make sure you are not saving the file in UTF-8 or UTF-16 format (look in your program's Save As dialog for options).

Re: Login page error

Posted: Tue Jan 20, 2009 8:12 am
by Greg19
yeah everything checks out there, any other ideas? -thanks

Re: Login page error

Posted: Tue Jan 20, 2009 8:17 am
by novice4eva
lose the session_start() at line 33

Re: Login page error

Posted: Tue Jan 20, 2009 8:17 pm
by Greg19
nope, still getting the error message.

edit: never mind, it works now. thanks a bunch :D