4 Replies Latest reply on Nov 1, 2010 1:22 AM by rongrace1

    Session start error

    rongrace1

      I'm using Dreamweaver with PHP. I've created a basic login page, but when I view it in an external browser of Live View I get the following errors. I've checked through various forum answers and know it's defintely nothing to do with extra spaces/characters before or after the <php> tag. One thing that does confuse is that the path the error quotes is incorrect, the path of the loginform.php is actually c:\wamp\www\hanson\loginform.php, any help would be appreciated, and by the way I'm a newbie with PHP

       

      Warning: session_start() [function.session-start]: Cannot send session  cookie - headers already sent by (output started at C:\wamp\www\loginform.php:1)  in C:\wamp\www\loginform.php on line 0

       

      Warning:  session_start() [function.session-start]:  Cannot send session cache limiter - headers already sent (output started at  C:\wamp\www\loginform.php:1) in C:\wamp\www\loginform.php on line  0

       

      Code for loginform.php

       

      <?php virtual('/Connections/Hanson.php'); ?>
      <?php
      ob_start();
      if (!function_exists("GetSQLValueString")) {
      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      {
        if (PHP_VERSION < 6) {
          $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        }
        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
        switch ($theType) {
          case "text":
            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
            break;   
          case "long":
          case "int":
            $theValue = ($theValue != "") ? intval($theValue) : "NULL";
            break;
          case "double":
            $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
            break;
          case "date":
            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
            break;
          case "defined":
            $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
            break;
        }
        return $theValue;
      }
      }
      mysql_select_db($database_Hanson, $Hanson);
      $query_rs_UsersFull = "SELECT * FROM security";
      $rs_UsersFull = mysql_query($query_rs_UsersFull, $Hanson) or die(mysql_error());
      $row_rs_UsersFull = mysql_fetch_assoc($rs_UsersFull);
      $totalRows_rs_UsersFull = mysql_num_rows($rs_UsersFull);
      ?>
      <?php
      // *** Validate request to login to this site.
      if (!isset($_SESSION)) {
        session_start();
      }
      $loginFormAction = $_SERVER['PHP_SELF'];
      if (isset($_GET['accesscheck'])) {
        $_SESSION['PrevUrl'] = $_GET['accesscheck'];
      }
      if (isset($_POST['opno'])) {
        $loginUsername=$_POST['opno'];
        $password=$_POST['pass_word'];
        $MM_fldUserAuthorization = "";
        $MM_redirectLoginSuccess = "/menu.php";
        $MM_redirectLoginFailed = "/loginform.php";
        $MM_redirecttoReferrer = false;
        mysql_select_db($database_Hanson, $Hanson); 
        $LoginRS__query=sprintf("SELECT opno, opname FROM security WHERE opno=%s AND opname=%s",
          GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
        $LoginRS = mysql_query($LoginRS__query, $Hanson) or die(mysql_error());
        $loginFoundUser = mysql_num_rows($LoginRS);
        if ($loginFoundUser) {
           $loginStrGroup = "";   
          //declare two session variables and assign them
          $_SESSION['MM_Username'] = $loginUsername;
          $_SESSION['MM_UserGroup'] = $loginStrGroup;        

       

          if (isset($_SESSION['PrevUrl']) && false) {
            $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];   
          }
          header("Location: " . $MM_redirectLoginSuccess );
        }
        else {
          header("Location: ". $MM_redirectLoginFailed );
        }
      }
      ?>
      <!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=utf-8" />
      <title>Login</title>
      </head>
      <body>
      <p>Please Log In</p>
      <form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
        <table>
          <tr>
            <td>User Name :</td>
            <td><input type="text" name="opno" id="opno" /></td>
          </tr>
          <tr>
            <td>Password :</td>
            <td><input type="password" name="pass_word" id="pass_word" /></td>
          </tr>
          <tr>
            <td> </td>
            <td><input type="submit" name="submit" id="submit" value="Login" /></td>
          </tr>
        </table>
      </form>
      <p> </p>
      </body>
      </html>
      <?php
      mysql_free_result($rs_UsersFull);
      ?>

       

      Code for the connectiosn file

       

      <?php
      # FileName="Connection_php_mysql.htm"
      # Type="MYSQL"
      # HTTP="true"
      $hostname_Hanson = "localhost";
      $database_Hanson = "hanson";
      $username_Hanson = "root";
      $password_Hanson = "";
      $Hanson = mysql_pconnect($hostname_Hanson, $username_Hanson, $password_Hanson) or trigger_error(mysql_error(),E_USER_ERROR);
      ?>

        • 1. Re: Session start error
          w1n78 Level 2

          move

          <?php
          // *** Validate request to login to this site.
          if (!isset($_SESSION)) {
            session_start();
          }
          $loginFormAction = $_SERVER['PHP_SELF'];
          if (isset($_GET['accesscheck'])) {
            $_SESSION['PrevUrl'] = $_GET['accesscheck'];
          }
          if (isset($_POST['opno'])) {
            $loginUsername=$_POST['opno'];
            $password=$_POST['pass_word'];
            $MM_fldUserAuthorization = "";
            $MM_redirectLoginSuccess = "/menu.php";
            $MM_redirectLoginFailed = "/loginform.php";
            $MM_redirecttoReferrer = false;
            mysql_select_db($database_Hanson, $Hanson);  
            $LoginRS__query=sprintf("SELECT opno, opname FROM security WHERE opno=%s AND opname=%s",
              GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));  
            $LoginRS = mysql_query($LoginRS__query, $Hanson) or die(mysql_error());
            $loginFoundUser = mysql_num_rows($LoginRS);
            if ($loginFoundUser) {
               $loginStrGroup = "";    
              //declare two session variables and assign them
              $_SESSION['MM_Username'] = $loginUsername;
              $_SESSION['MM_UserGroup'] = $loginStrGroup;         
          

           

              if (isset($_SESSION['PrevUrl']) && false) {

           

                $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  

           

              }

           

              header("Location: " . $MM_redirectLoginSuccess );

           

            }

           

            else {

           

              header("Location: ". $MM_redirectLoginFailed );

           

            }

           

          }

           

          ?>

           

           

           

           

           

          below

          <?php virtual('/Connections/Hanson.php'); ?>
          

           

           

          header() can only be called before headers are printed on the page

          • 2. Re: Session start error
            rongrace1 Level 1

            Following you advice, the code now looks like this, but I'm still getting the errors below

             

            <?php virtual('/Connections/Hanson.php'); ?>
            <?php
            // *** Validate request to login to this site.
            if (!isset($_SESSION)) {
              session_start();
            }

             

            $loginFormAction = $_SERVER['PHP_SELF'];
            if (isset($_GET['accesscheck'])) {
              $_SESSION['PrevUrl'] = $_GET['accesscheck'];
            }

             

            if (isset($_POST['opno'])) {
              $loginUsername=$_POST['opno'];
              $password=$_POST['pass_word'];
              $MM_fldUserAuthorization = "";
              $MM_redirectLoginSuccess = "/menu.php";
              $MM_redirectLoginFailed = "/loginform.php";
              $MM_redirecttoReferrer = false;
              mysql_select_db($database_Hanson, $Hanson);
             
              $LoginRS__query=sprintf("SELECT opno, opname FROM security WHERE opno=%s AND opname=%s",
                GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
              
              $LoginRS = mysql_query($LoginRS__query, $Hanson) or die(mysql_error());
              $loginFoundUser = mysql_num_rows($LoginRS);
              if ($loginFoundUser) {
                 $loginStrGroup = "";
               
                //declare two session variables and assign them
                $_SESSION['MM_Username'] = $loginUsername;
                $_SESSION['MM_UserGroup'] = $loginStrGroup;        

             

                if (isset($_SESSION['PrevUrl']) && false) {
                  $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];   
                }
                header("Location: " . $MM_redirectLoginSuccess );
              }
              else {
                header("Location: ". $MM_redirectLoginFailed );
              }
            }

             

            if (!function_exists("GetSQLValueString")) {
            function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
            {
              if (PHP_VERSION < 6) {
                $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
              }

             

              $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

             

              switch ($theType) {
                case "text":
                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                  break;   
                case "long":
                case "int":
                  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                  break;
                case "double":
                  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                  break;
                case "date":
                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                  break;
                case "defined":
                  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                  break;
              }
              return $theValue;
            }
            }
            ?>

             


            ob_start();
            if (!function_exists("GetSQLValueString")) {
            function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
            {
              if (PHP_VERSION < 6) {
                $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
              }
              $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
              switch ($theType) {
                case "text":
                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                  break;   
                case "long":
                case "int":
                  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                  break;
                case "double":
                  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                  break;
                case "date":
                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                  break;
                case "defined":
                  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                  break;
              }
              return $theValue;
            }
            }
            ?>
            <!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=utf-8" />
            <title>Login</title>
            </head>
            <body>
            <p>Please Log In</p>
            <form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
              <table>
                <tr>
                  <td>User Name :</td>
                  <td><input type="text" name="opno" id="opno" /></td>
                </tr>
                <tr>
                  <td>Password :</td>
                  <td><input type="password" name="pass_word" id="pass_word" /></td>
                </tr>
                <tr>
                  <td> </td>
                  <td><input type="submit" name="submit" id="submit" value="Login" /></td>
                </tr>
              </table>
            </form>
            <p> </p>
            </body>
            </html>

             

             

            Warning: session_start() [function.session-start]: Cannot send session  cookie - headers already sent by (output started at  C:\wamp\www\loginform2.php:1) in C:\wamp\www\loginform2.php on line  0

             

            Warning: session_start() [function.session-start]: Cannot send session  cache limiter - headers already sent (output started at  C:\wamp\www\loginform2.php:1) in C:\wamp\www\loginform2.php on line  0
            ob_start(); if (!function_exists("GetSQLValueString")) { function  GetSQLValueString($theValue, $theType, $theDefinedValue = "",  $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue =  get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue =  function_exists("mysql_real_escape_string") ?  mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch  ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'"  : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ?  intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "")  ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue !=  "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue =  ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return  $theValue; } } ?>

            • 3. Re: Session start error
              w1n78 Level 2

              move the code above

              <?php virtual('/Connections/Hanson.php'); ?>
              

               

              don't know if it will work coz it might be relying on your connection file. if you still get an error, remove the code that you're moving around. do you still get an error? if you do, there's something wrong with that code. have DW re-write for you again.

              • 4. Re: Session start error
                rongrace1 Level 1

                Thanks w1n78, that worked. You'd think DW would code it correctly