Session
Posted: Fri Jan 19, 2007 5:55 pm
I am trying to retrieve the user id of a member from my login page, but I do not know how set the variable and retrieve it on that page.
Log In:
Here is the page where I want the sessions to appear. Now would I need to start a query to receive the users id and if I did how would I accomplish this?
Any help would be appreciated.
Thanks!
Log In:
Code: Select all
<?php
//login page
session_start();
session_register("username", "id", "gid");
require ("config.php");
//if entered blank form returns error
foreach ($_POST as $field => $value)
{
if ($value == "")
{
$blanks[] = $field;
}
}
if (isset ($blanks) )
{
$message = "Following fields are blank. Please enter the required information: ";
foreach ($blanks as $value)
{
$message .= "$value, ";
}
extract ($_POST);
include ('login_form.php');
exit();
}
//Define variables.
$username = trim($_POST['username']);
$password = trim($_POST['password']);
//time to select information
$sql ="SELECT `username`,`password`, `id`, 'gid' FROM members WHERE username = '$username' AND password = md5('$password')";
$result = mysql_query($sql, $con);
$row = mysql_fetch_assoc($result);
mysql_error();
//We check if username and password is correct
$num = mysql_numrows ($result);
if ($num != 0)
{
print "Welcome $username - your log-in succeeded!";
}
else
{
print "Wrong username or password";
}
?>Code: Select all
<?php
require ('config.php');
session_start();
header("Cache-control: no-cache");
print $username;
print $id; //Not sure how to set this one up
?>Thanks!