why isnt my session data defining id?
Posted: Wed Dec 02, 2009 1:15 pm
This is my login function
if i try echo out session data it leaves the $id blank
Code: Select all
function user_login($username, $password)
{
$thequery = ("SELECT registered FROM members WHERE username = '". $username ."' ");
$query = mysql_query($thequery) or die ('session data dont match.');
$row = mysql_fetch_array($query);
$result = $row['registered'];
if($result == 0)
{
// Reshow the form with an error
$notregistered_error = 'username not registered';
include 'index.php';
exit;
}
// Try and get the salt from the database using the username
$query = ("select salt from members where username='$username' limit 1");
$result = mysql_query($query);
$user = mysql_fetch_array($result);
// Using the salt, encrypt the given password to see if it
// matches the one in the database
$encrypted_pass = md5(md5($password).$user['salt']);
// Try and get the user using the username & encrypted pass
$query = "SELECT id, username FROM members WHERE username='$username' and password='$encrypted_pass'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
$numrows = mysql_num_rows($result);
// Now encrypt the data to be stored in the session
$encrypted_id = md5($user['id']);
$encrypted_name = md5($user['username']);
// Store the data in the session
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
if ($numrows == 1)
{
return 'Correct';
}
else
{
return false;
}
}Code: Select all
<?php
if (!isset($_SESSION)) {
session_start();
}
echo '<pre>';
print_r( $_SESSION );
echo '</pre>';
?>