i want a simple user login without database.

Discussion in 'PHP' started by Kyriakos, Apr 20, 2008.

  1. #1
    hi everyone,

    how to create a simple user login without database? i want to write in a php page (validation.php) the usernames and passwords, to create a cookie for each user and each page to has a validation script. can anybody give some help?

    thanks in advance.
     
    Kyriakos, Apr 20, 2008 IP
  2. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Would've thought something like this should be sufficient:

    if( $_POST["user"] == "user1" && $_POST["pass"] == "pass" ) {
    	// User #1: Info is correct, do whatever...
    	$_SESSION["user"] = $_POST["user"];
    	echo "Logged in as: ". $_SESSION["user"];
    } elseif( $_POST["user"] == "user2" && $_POST["pass"] == "pass" ) {
    	// User #2: Info is correct, do whatever...
    	$_SESSION["user"] = $_POST["user"];
    	echo "Logged in as: ". $_SESSION["user"];
    } else {
    	// User enter wrong info, do whatever...
    	echo "No.";
    }
    PHP:
    This is presuming you're using a form which uses POST as the method.

    Then on pages where you want to see if they are logged in or not:

    if( !isset( $_SESSION["user"] ) {
    	// User isn't logged in. Probably re-direct them to the login form...
    	echo "Not logged in.";
    	die( );
    } else {
    	// User is logged in, do whatever...
    	echo "Welcome to the secret members only area!";
    }
    PHP:
     
    Xtrm2Matt, Apr 20, 2008 IP