login help

    Date: 01/17/07 (PHP Community)    Keywords: php, mysql, html, database, sql

    I'm trying to create a super basic login page.. one that doesn't require a mysql database of usernames and passwords, which apparently is nearly impossible to find. I'm still relatively new to php.. bumbling along mostly. Anyway.. here's what I've got so far



    In the first page of the protected section:


    session_start();
    if (isset($_POST['user'])) {
    $_SESSION['username'] = $_POST['user'];
    $_SESSION['password'] = $_POST['pass'];
    $_SESSION['authuser'] = 0;
    }
    //check username and password information
    if (($_SESSION['username'] == 'bob') and
    ($_SESSION['password'] == 'smith')) {
    $_SESSION['authuser'] = 1;
    } else {
    echo "Sorry, but you don't have permission to view this page, Try Again";
    exit();
    }
    ?>




    What I'm trying to accomplish is being able to kill this information with a "Logout" button. I've attempted putting session_destroy() and session_unset(); in the header of that page.. tried resetting the $_POST['user'] to nothing or something other than 'bob' (and changing the isset part.)

    Nothing works.. I'm still passing something that's allowing me to be logged in.

    How can I code this so it's totally killed.. dead, gone.. when they hit a button that says logout ??



    for the rest of the pages can I simply put in the header

    session_start();
    if ($_SESSION['authuser'] = 1) {
    ?>

    html stuffs

    else {
    echo "Sorry, but you don't have permission to view this page, Try Again";
    exit();
    }
    ?>



    you guys are my last hope.. I'm about to toss the whole thing and resort to .htaccess .. please help!

    ETA: Problem appears to be fixed.. thanks everyone!

    Source: http://community.livejournal.com/php/530638.html

« losing my patience... || newbie!!! »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home