Sessions question
Posted: Tue Sep 11, 2007 4:02 pm
I'm trying to make a login page that directs the user to a page where they can edit the news mysql table. The problem I have is I can't seem to get the members page to get the $username of the person logged in. I am probably completely wrong from what I have so far, but from my little knowledge of what I've been practicing it looks right to me.
login.php
members.php
It members.php right now opens a blank page, it does not return to the login.php like its suppose to. HELP! It's driving me crazy 
login.php
Code: Select all
<?php
session_start();
include 'dbdata.txt';
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
$username = htmlentities($_POST['username']);
$password = htmlentities($_POST['password']);
if(isset($_POST['username']) && $_POST['password'])
{
$query = "SELECT * FROM users WHERE user_name = '$username' AND password = '$password'";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
if(mysql_num_rows($result) == 1)
{
$_SESSION['login'] = $username;
$_SESSION['password'] = $password;
header("Location: members.php");
}
//the form and stuff down here
}
?>Code: Select all
<?php
session_start();
include 'dbdata2.txt';
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
if (!isset($_SESSION['login']))
{
header('Location: login.php');
}
else if(isset($_SESSION['login']))
{
echo "<html><head><title>Make Some Damn News!</title></head><body> Welcome <b>$_SESSION['login']</b> <a href=\"logout.php\">logout</a>";
}
else
{
echo "I guess I don't know how to work Sessions";
}
?>