Jump to content

Archived

This topic is now archived and is closed to further replies.

hemlock

Show the user name based on login

Recommended Posts

Thanks in advance for any help provided for a new user of PHP. I have a login page that brings users to this page displayed below. I would like to display the users first name on the page and use the user ID to insert data back into the database with other data from a form that I have not yet created. I need to keep track of the user that entered the data in the database. The pages were created with server behaviors from Dreamweaver. Where is the user name stored from the login? Thanks again for any help with the code or more information about the user name info.


<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "logoutthankyou.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  // For security, start by assuming the visitor is NOT authorized.
  $isValid = False;

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  if (!empty($UserName)) {
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
    // Parse the strings into arrays.
    $arrUsers = Explode(",", $strUsers);
    $arrGroups = Explode(",", $strGroups);
    if (in_array($UserName, $arrUsers)) {
      $isValid = true;
    }
    // Or, you may restrict access to only certain users based on their username.
    if (in_array($UserGroup, $arrGroups)) {
      $isValid = true;
    }
    if (($strUsers == "") && true) {
      $isValid = true;
    }
  }
  return $isValid;
}

$MM_restrictGoTo = "Pleaselogin.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { 
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Time Entry</title>
<link href="BLUE APS.css" rel="stylesheet" type="text/css" />
</head>

<body>
<p align="center" class="style1">APS</p>
<p>Welcome,
<p>&nbsp;</p>

   
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;<a href="<?php echo $logoutAction ?>">Log out</a></p>
<p>&nbsp;</p>
<p>&nbsp; </p>
</body>
</html>

Share this post


Link to post
Share on other sites
You could echo the $_SESSION first name where you want the name to appear assuming that you have registered sessions when the user logs in

Share this post


Link to post
Share on other sites
Sorry I did not notice the Dreamweaver PHP Help. Thanks for moving this post to the right place.

Share this post


Link to post
Share on other sites
[quote author=AdRock link=topic=106345.msg425270#msg425270 date=1157019845]
You could echo the $_SESSION first name where you want the name to appear assuming that you have registered sessions when the user logs in
[/quote]

Thanks for the suggestion. I am using a server behavior to force users to login if they go straight to this page without logging in. So I would assume that a session is keeping track of that. I understand how to use a echo. What would the $_session part look like in the echo? I was trying to figure out where to get that from and how to enter it for the desired result. I also would like to use it to enter into MYSQL database.

Share this post


Link to post
Share on other sites
Nasty! DW code. But the session variable you'll want use is $_SESSION['MM_Username']

Share this post


Link to post
Share on other sites
I wish that I could write my code with out the help of Dreamweaver. But I still have much to learn.

Thanks

Share this post


Link to post
Share on other sites

×

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.