Help with session_start()

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default Help with session_start()

    Hi. I was tring to start a session my web page and tried using the
    session_start(). However i keep gettin the warning:

    Warning: session_start() [function.session-start]: Cannot send session cookie
    - headers already sent by (output started at c:\wamp\www\********\index.php:3)
    in c:\wamp\www\*******\index.php on line 4.

    Am I gettin this error cause im hand coding. What should i do to correct it?

    Gamespy007 Guest

  2. Similar Questions and Discussions

    1. Session_Start not firing
      I'm workinbg in Visual Studio 2003. I'm experimenting with creating a session variable, and from all I can gather. the Session_Start event is not...
    2. Classes and session_start()
      Hello there! I'm building a php system where I can put images in a zipfile and download it. I found some code to do this and created zip.php, a...
    3. session_start() problem
      Hi, every time. This is a familiar question here, but the answers I found in this and other groups did not help. I get the : Warning: Cannot send...
    4. About Session_Start() with different Browser
      Hi all, I am new to php. At first, I wrote a php script to generate a pdf file from a tex file and load that pdf file to the browser by call a...
    5. session_start()
      Ian.H wrote: Just one clarification for the original poster, as I think this still might be semi-unclear to him. (Had he understood the manual...
  3. #2

    Default Re: Help with session_start()

    Gamespy007 wrote:
    > Hi. I was tring to start a session my web page and tried using the
    > session_start(). However i keep gettin the warning:
    >
    > Warning: session_start() [function.session-start]: Cannot send session cookie
    > - headers already sent by (output started at c:\wamp\www\********\index.php:3)
    > in c:\wamp\www\*******\index.php on line 4.
    >
    > Am I gettin this error cause im hand coding.
    no
    > What should i do to correct it?
    as the message states, you can't send a session cookie after the headers
    have been sent (unless you're using output buffering)

    probably there is a space/blank line sended before or an HTML tag. post
    the first lines of your code to see what's the problem

    John Doe Guest

  4. #3

    Default Re: Help with session_start()

    I think i got the session_start() to work. But now i get the error of:

    Warning: Cannot modify header information - headers already sent by (output
    started at: c:\wamp\www\cyberstudents\db.php:15) in
    c:\wamp\www\**********\login.php on line 45

    There is something wrong with my header call to return to the index page. The
    code im using is:

    <?php
    session_start();
    include'db.php';

    $username = $_POST['username'];
    $password_usr = $_POST['password_usr'];

    // checkin if the user exists
    $sql_user_check = "SELECT * FROM users WHERE username='$username'";
    $result_name_check = mysql_query($sql_user_check);
    $usersfound = mysql_num_rows($result_name_check);
    // if user not found, note that and end
    if ($usersfound < 1) {
    $error = "User $user not found.";
    // if user does exist, continue with processing
    } else {
    // checking if passwords match
    $sql_pass_get = "SELECT * FROM users WHERE username='$username'";
    $user_info = mysql_fetch_array(mysql_query($sql_pass_get));
    $password = $user_info['password_usr'];
    // if doesn't match, note that and end
    if ($password != $password_usr) {
    $error = "Invalid password. Try again.";
    // if do match, let in and pass on info to session variables
    } else {
    $_SESSION['usr_id'] = $user_info['usr_id'];
    $_SESSION['username'] = $user_info['username'];
    $_SESSION['password_usr'] = $user_info['password_usr'];
    $_SESSION['email_address'] = $user_info['email_address'];
    $_SESSION['firstname_usr'] = $user_info['firstname_usr'];
    $_SESSION['lastname_usr'] = $user_info['lastname_usr'];
    $_SESSION['level_usr'] = $user_info['level_usr'];
    $_SESSION['regtime_usr'] = $user_info['regtime_usr'];
    }
    }
    if (!$_SESSION['username']) {
    if ($error) {
    echo $error;
    include 'login.html';
    } else {
    include 'index.php';

    }
    } else {
    header("Location: index.php");
    exit;
    }
    ?>


    The db.php file is:
    <?
    # database connection scripts
    # the next 4 lines you can modify
    $dbhost = 'localhost';
    $dbusername = 'root';
    $dbpasswd = 'password';
    $database_name = 'cyberstudents';
    #under here, don't touch!
    $connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd" )
    or die ("Couldn't connect to server.");
    $db = mysql_select_db("$database_name", $connection)
    or die("Couldn't select database.");
    ?>



    Gamespy007 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139