SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot codewrecker's Avatar
    Join Date
    Feb 2002
    Location
    U.S.A.
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sessions problem

    I was using the script from Kevins sessions article and am having some problems..keep getting this message

    Warning: Cannot send session cookie - headers already sent by (output started at /home/path/public_html/Admin/common.php:2)

    Warning: Cannot send session cache limiter - headers already sent (output started at /home/path/public_html/cpafishing/Admin/common.php:2)

    any ideas what the problem is based on the error message?

    thanks
    CodeWrecker

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It means that information has been written to the browser before the session has been started

    Make sure you're session code is above any input (ie print statements or HTML).

    If you are still having problems post your code here!

  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    session_start();

    should be right after:

    <?php
    John

  4. #4
    SitePoint Zealot codewrecker's Avatar
    Join Date
    Feb 2002
    Location
    U.S.A.
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK got past that one. thanks! now next problem..I include sesssoncontrol.php at the top of every page. When I log into a page everything is ok. The problem comes when I navigate to a new page. The script asks me to either sign up or log in again. Once I log in it lets me have access...is something wrong with the sessions?? Here's the code:
    PHP Code:
    <?php // accesscontrol.php
    session_start();
    include(
    "common.php" );
    include(
    "db.php" );
    if(!isset(
    $uid)) {
    ?>
    <html>
    <head>
    <title> Please Log In for Access </title>
    </head>
    <body>
    <h1> Login Required </h1>
    <p>You must log in to access this area of the site. If you are
    not a registered user, <a href="signup.php">click here</a>
    to sign up for instant access!</p>
    <p><form method="post" action="<?=$PHP_SELF?>">
    User ID: <input type="text" name="uid" size="8"><br>
    Password: <input type="password" name="pwd" SIZE="8"><br>
    <input type="submit" value="Log in">
    </form></p>
    </body>
    </html>
    <?php
    exit;
    }

    session_register("uid" );
    session_register("pwd" );

    dbConnect("xxxxxxx" );
    $sql "SELECT * FROM user WHERE
    userid = '
    $uid' AND password = '$pwd'";
    $result mysql_query($sql);
    if (!
    $result) {
    error("A database error occurred while checking your ".
    "login details.\\nIf this error persists, please ".
    "contact xxxxxxxxx." );
    }
    if (
    mysql_num_rows($result) == 0) {
    session_unregister("uid" );
    session_unregister("pwd" );
    ?>
    <html>
    <head>
    <title> Access Denied </title>
    </head>
    <body>
    <h1> Access Denied </h1>
    <p>Your user ID or password is incorrect, or you are not a
    registered user on this site. To try logging in again, click
    <a href="<?=$PHP_SELF?>">here</a>. To register for instant
    access, click <a href="signup.php">here</a>.</p>
    </body>
    </html>
    <?php
    exit;
    }
    $username mysql_result($result,0,"fullname" );
    ?>
    CodeWrecker

  5. #5
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is enable_globals on?

    try using the $_SESSION array for variables.

  6. #6
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like this might be a 'register globals' problem. I'll let Kevin do the explaining himself :
    http://www.sitepoint.com/article/758

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  7. #7
    SitePoint Zealot codewrecker's Avatar
    Join Date
    Feb 2002
    Location
    U.S.A.
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I've tried using $_POST, $_SESSION, and $_GET. Still can't get the script to work. I read Kevins article but I guess I'm just too dense to make his advise work with this script. Unfortunately I'm just not getting it images/smilies/confused.gif

    PHP Code:
     <?php // accesscontrol.php
    session_start();
    $username $_POST['fullname'];
    $uid $_POST['uid'];
    $pwd $_POST['pwd'];
    $PHP_SELF $_SERVER['PHP_SELF'];

    include(
    "common.php" );
    include(
    "db.php" );


    if(!isset(
    $uid)) {
    ?>
    <html>
    <head>
    <title> Please Log In for Access </title>
    </head>
    <body>
    <h1> Login Required </h1>
    <p>You must log in to access this area of the site. If you are
    not a registered user, <a href="signup.php">click here</a>
    to sign up for instant access!</p>
    <p><form method="post" action="<?=$PHP_SELF?>">
    User ID: <input type="text" name="uid" size="8"><br>
    Password: <input type="password" name="pwd" SIZE="8"><br>
    <input type="submit" value="Log in">
    </form></p>
    </body>
    </html>
    <?php
    exit;
    }

    session_register("uid" );
    session_register("pwd" );

    dbConnect("xxxxx_articledb" );
    $sql "SELECT * FROM user WHERE
    userid = '
    $uid' AND password = '$pwd'";
    $result mysql_query($sql);
    if (!
    $result) {
    error("A database error occurred while checking your ".
    "login details.\\nIf this error persists, please ".
    "contact [email=xxxxx@msn.com]xxxxxxx@msn.com[/email]." );
    }
    if (
    mysql_num_rows($result) == 0) {
    session_unregister("uid" );
    session_unregister("pwd" );
    ?>
    <html>
    <head>
    <title> Access Denied </title>
    </head>
    <body>
    <h1> Access Denied </h1>
    <p>Your user ID or password is incorrect, or you are not a
    registered user on this site. To try logging in again, click
    <a href="<?=$PHP_SELF?>">here</a>. To register for instant
    access, click <a href="signup.php">here</a>.</p>
    </body>
    </html>
    <?php
    exit;
    }
    $username mysql_result($result,0,"fullname" );
    ?>
    CodeWrecker


Bookmarks

Posting Permissions

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