Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    hello buddies ...

    i am trying following code for logging and logout script..but its not working...i have created following database

    CREATE DATABASE mydatabase;
    USE mydatabase;

    CREATE TABLE users {
    userId SMALLINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
    userName VARCHAR(30) NOT NULL,
    userPass VARCHAR(32) NOT NULL,
    PRIMARY KEY (userId),
    UNIQUE KEY username (username)
    }

    and then inserted following values:
    INSERT INTO users (userName, userPass) VALUES ('testUser', MD5('testPass'));

    and then wrote this script:...
    <?PHP

    $db = mysql_connect('localhost', 'dbuser', 'dbpass') or die("Couldn't connect to the database.");
    mysql_select_db('dbname') or die("Couldn't select the database");

    // Add slashes to the username, and make a md5 checksum of the password.
    $_POST['user'] = addslashes($_POST['user']);
    $_POST['pass'] = md5($_POST['pass']);

    $result = mysql_query("SELECT count(id) FROM users WHERE password='$_POST[pass]' AND username='$_POST[user]'") or die("Couldn't query the user-database.");
    $num = mysql_result($result, 0);

    if (!$num) {

    // When the query didn't return anything,
    // display the login form.

    echo "<h3>User Login</h3>
    <form action='$_SERVER[PHP_SELF]' method='post'>
    Username: <input type='text' name='user'><br>
    Password: <input type='password' name='pass'><br><br>
    <input type='submit' value='Login'>
    </form>";

    } else {

    // Start the login session
    session_start();

    // We've already added slashes and MD5'd the password
    $_SESSION['user'] = $_POST['user'];
    $_SESSION['pass'] = $_POST['pass'];

    echo "<h1>Congratulations</h1>";
    echo "You're now logged in. Try visiting <a href='page2.php'>Page 2</a>.";
    }
    ?>

    but its giving me error like :
    Notice: Undefined index: user in g:\inetpub\wwwroot\test.php on line 7

    Notice: Undefined index: pass in g:\inetpub\wwwroot\test.php on line 8

    but its giving me the username and password field ...and if i ignore the errors and fill the form it directs me to the same page without any error on it ...i want to get directed to page2.php

    i know i am missing some silly thing...but couldn't find it ..pls help me out

    Anant

  2.  

  3. #2
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    It looks as though it's because you're trying to assign a value to a variable with a variable that doesn't exist.

    ie:

    $_SESSION['user'] = $_POST['user'];
    $_SESSION['pass'] = $_POST['pass'];

    Before the form has been filled in once $_POST['xxxx'] is not assigned. Trying to assign a value to a variable from an array that doesn't exist won't work.

    Try this:

    if (isset($_POST['user']) and isset($_POST['pass'])) {
    $_SESSION['user'] = $_POST['user'];
    $_SESSION['pass'] = $_POST['pass'];
    }

  4. #3
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    hi ...

    tried what u said .... but its not working it still says the same problem...

    tell me one thing i have installed php on IIS ...is that something i have to change , while running the session...in php...i have installed php as installer..
    pls help me out

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Quote Originally Posted by Anant
    tell me one thing i have installed php on IIS ...is that something i have to change , while running the session...in php...i have installed php as installer..
    pls help me out
    That, was a bit foggy!

    However, installing PHP on IIS, doesn't normally constitute any problems. There are no extra settings or tweaks neccessary, to make it run smoothly.

    I have installed PHP on both IIS and Apache (equaly divided), and they all run fine. Most things that deals with how sessions are treated etc, are subject to alterations in the php.ini file (in combination with DB and script), not the server instance itself.

    I would have written the code a bit different, but haven't had time to scrutinize yours.
    S. Rosland

  6. #5
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    Quote Originally Posted by rosland
    That, was a bit foggy!

    However, installing PHP on IIS, doesn't normally constitute any problems. There are no extra settings or tweaks neccessary, to make it run smoothly.

    I have installed PHP on both IIS and Apache (equaly divided), and they all run fine. Most things that deals with how sessions are treated etc, are subject to alterations in the php.ini file (in combination with DB and script), not the server instance itself.

    I would have written the code a bit different, but haven't had time to scrutinize yours.
    can i have ur code for this .... i have to authenticate one web page in my web site and to craete a logout also...
    pls help


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:44 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com