Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    Ottawa, ON
    Posts
    1

    Unanswered: sessions, getting an error :(

    hello all..

    i am new to php. i am trying to make a login page. i want to use session variables. i have two questions:

    Question 1.
    Should i register my session variables in login.php (this is simply an html form with username and password text boxes right now) or should i register them in the .php that is called when the submit button is pressed?

    Question 2.

    I tried registering them in the .php that is called when submit is pressed. but i get these two errors:

    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\schedule\scripts\test.php:2) in c:\program files\apache group\apache\htdocs\schedule\scripts\test.php on line 3



    and,

    Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0


    I have no idea what could possibly be wrong!

    in case you are interested, here is my code so far for the test.php file.


    <?
    session_start();
    session_register("uname","passw");

    ?>

    <h1>
    <?php global $st; ?>
    <?php
    $uname= $_POST["u_name"];
    $passw= $_POST["pwd"];
    //echo "$passw";
    //session_register("uname","passw");


    ?>
    <h1/>

    i hope you guys can help me out! i'm really stuck! thanks in advance!

  2. #2
    Join Date
    Mar 2004
    Location
    Nashville, IN
    Posts
    5
    Watch out for blank lines and spaces. They can cause output (and the header to be sent). Here's some code where I start a session. Hope it helps:

    <?php
    // This page puts up one of three pages depending upon the session status.
    // If the other admin forms don't detect the session, they redirect to this page.
    // Also can link back to this page so see if session started already.
    session_start();
    if (!isset($_SESSION['pwd'])){
    if (isset($_POST['submit'])):
    // An ID has been submitted. Quit if the wrong one
    $uid = $_POST['uid'];
    if($uid != '*******'){ //(I actually have a pswd coded here)
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="CSstyle.css" rel="stylesheet" type="text/css">
    <title>Invalid ID</title>
    </head>
    <body>
    <?php
    die('<h2>Invalid ID entered.</h2>');
    ?>
    </body>
    </html>
    <?php
    } else {
    // The right ID was entered so start a session
    session_start();
    if (!isset($_SESSION['pwd']))
    $_SESSION['pwd'] = $uid;
    }
    else: // no session and not submit so put up pw form
    ?>
    <html>
    <head>
    .
    .
    .

  3. #3
    Join Date
    Mar 2004
    Posts
    3
    Apparently, you are using IE.
    This is an IE problem in my experience.
    There is however, a way of getting around it.
    Yo need to add the line:
    header("Cache-Control: Private");
    before you start the session, ie...

    <?
    header("Cache-Control: Private");
    session_start();
    if ($_GET['logout'] == 1) {
    session_destroy();
    session_start();
    }
    if (!$_SESSION['auth']) {
    $_SESSION['auth'] = 0;
    }
    ?>

    theone | suicidle.com

Posting Permissions

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