SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Sessions

  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Santa Campaign HQ
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I Have the code:
    PHP Code:
    <?php
    session_start
    ();
        if(!isset(
    $username)) {
            
    ?>
                <html>
                <head>
                <title> Please Log In for Access </title>
                </head>
                <body>
                <h1><font face=verdana,arial> 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="username" size="8">
                <br>
                Password: <input type="password" name="password" SIZE="8">
                <br>
                <input type="submit" value="Log in">
                </form>
                </p>
                </body>
                </html>
                <?php
                
    exit;
            }
    session_register("username");
    session_register("password");

    require(
    "functions.php");
    dbConnect();
    $sql "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
    $result mysql_query($sql);
    if (!
    $result) {
        
    error("A database error occurred while checking your ".
              
    "login details.\\nIf this error persists, please ".
              
    "contact [email]kevin@sitepoint.com[/email].");
        }
    if (
    mysql_num_rows($result) == 0) {
        
    session_unregister("username");
        
    session_unregister("password");
        
    ?>
            <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,"username");
    ?>
    and on my local webserver (phpdev3 for win95) it gives me the error:

    Warning: Cannot send session cache limiter - headers already sent (output started at c:\phpdev3\www\testpage.php:6) in auth.php on line 2

    any help appreciated

    Alex
    A vote for LemonZone is a vote for more presents!!
    Campaigning to become the next santa since 1996!

  2. #2
    SitePoint Enthusiast DCE's Avatar
    Join Date
    Feb 2001
    Location
    UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a raw newbie at this, but I had a similar problem, so it may help

    You must have

    <?php
    session_start();

    At the very begining of the script, not even a single white space before it or it bombs out.
    hope that was some help
    DCE
    If everything seems to be going well, you have obviously overlooked
    something.

  3. #3
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right. The session start writes cookie info in the header so this must be done before any output is generated.


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
  •