Jump to content

session


Return

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

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.