Jump to content

Login page with member levels


mallen

Recommended Posts

I am creating a simple log in form to protect a "member" page. What i have done is assigned a "1" or a "2" to each subscriber. Only people with "2" can view the member page. Here is what I have so far. Its rough I know. I have some pseudo code in there just to get the outline right.

 

There are three pages. The member page that I am protecting, the login page that takes the submitted data, and the register page they get directed to if the log in fails.

----------------------------------------------------

member page

----------------------------------------------------

<?php

session_start();

$status = $status[0]; //member or not. If status "1" direct to register.php, if "2" show page.

session_register ('email');

session_register ('password');

session_register ('status');

 

if (isset ($POST['submit'])) {

if ((!empty ($_POST['email']))

 

if email and user name are a match when sent to login.php 

//show content on page below//

//All content will go here.....///

 

else

//print form to sign in

print '<p>Please sign in using your email address and your password</p>';

 

print '<form action=login.php" method="post"><p>Email: <input type="text" name="email" size="20" /><br/>

Password: <input type="password" name="password" size="20" /><br /> <input type="submit" name="submit" value=Log in /></p> </form>';

?>

 

---------------------------------------------

The login.php page

---------------------------------------------

<?php $username=$_POST['email'];//get data posted from members form

$password=$_POST['password'];

$success = "members.php";

$failed = "register.php";

//check user's email and password. Also if status is "1" redirect to register.php

//if status is "2" redirect to members.php and show the page.

SELECT email, password, and status FROM members

if email and password are ok and status is "2" then go to members page. Show as logged in.

else

if status is "1" redirect to register page.

 

Link to comment
Share on other sites

I found some script to use and I modified it. Does anything here look incorrect? Becuase it gives me the message "Sorry, could not log you in. Wrong login information." All I am doing is checking for "email" and "password"

 

<?php
session_start();
require_once('./Connections/....'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if ($_GET["op"] == "login")
{
if (!$_POST["email"] || !$_POST["password"])
  {
  die("You need to provide a username and password.");
  }

// Create query
$q = "SELECT * FROM `members` "
."WHERE `email`='".$_POST["email"]."' "
  ."AND `password`= PASSWORD('".$_POST["password"]."') "
  ."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["email"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php");
  }
else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");

  }
}
else
{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"email\"><br />";
echo "Password: <input name=\"password\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.