Jump to content

log in members only page not working help please


sandbudd

Recommended Posts

Have created sign in and members page.  The code is designed that if verified it goes to members.php if not it goes back to login.php.  I know that it is connecting to the database fine because it goes back to login rather than incorrect pass.  Please help as I have tried everything that I can.

 

here is login page:

 

<?php

session_start();

// dBase file

include "dbConfig.php";

 

if ($_GET["op"] == "login")

{

if (!$_POST["username"] || !$_POST["password"])

  {

  die("You need to provide a username and password.");

  }

 

// Create query

$q = "SELECT * FROM `dbUsers` "

  ."WHERE `username`='".$_POST["username"]."' "

  ."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["username"];

  $_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=\"username\" size=\"15\"><br />";

echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";

echo "<input type=\"submit\" value=\"Login\">";

echo "</form>";

}

?>

 

Here is members

 

<?php

session_start();

 

if (!$_SESSION["valid_user"])

{

// User not logged in, redirect to login page

Header("Location: login.php");

}

 

// Member only content

// ...

// ...

// ...

 

// Display Member information

echo "<p>User ID: " . $_SESSION["valid_id"];

echo "<p>Username: " . $_SESSION["valid_user"];

echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

 

// Display logout link

echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";

?>

 

any help would be great!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.