Jump to content

Recommended Posts

* I have a field in a db table called "name", as would be helping me to record it in a session to be viewing this page?

 

* Here is the code that the user uses to login.

 

<?php
 
include ('smarty/libs/Smarty.class.php');$smarty = new Smarty();
 $smarty->template_dir = "smarty/demo/templates";
$smarty->compile_dir = "smarty/demo/templates_c";
$smarty->config_dir = "smarty/demo/configs";
$smarty->cache_dir = "smarty/demo/cache";
?>
<?php
 
session_start();
 
if($_POST) {
include ('config.php');
$username = $_POST['username'];
$password = $_POST['password'];
 
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5($password)));
$result = mysql_query($query);
list($count) = mysql_fetch_row($result);
if($count >= 1) {
 
$_SESSION['authenticated'] = true;
$_SESSION['username'] = $username;
 
$query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')AND confirmed='1'",
mysql_real_escape_string($username),
mysql_real_escape_string(($confirmed)));
$result = mysql_query($query);
list($count) = mysql_fetch_row($result);
if($count == 1) {
 
$query = sprintf("UPDATE users SET last_login = NOW() WHERE UPPER(username) = UPPER('%s') AND password = '%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5($password)));
mysql_query($query);
 
$query = sprintf("SELECT is_admin FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string(md5($password)));
$result = mysql_query($query);
list($is_admin) = mysql_fetch_row($result);
if($is_admin == 1) {
 
print"<script> window.location='';</script>";
 
} else {
 
print"<script> window.location='';</script>";
 
}
}
 
$error = '';
 
}else{
 
$error = '';
 
}
}
 
$smarty->assign('error',$error);
$smarty->assign('message',$message);
$smarty->display('login.tpl');

?>

Link to comment
https://forums.phpfreaks.com/topic/281482-session/
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.