Jump to content


Photo

Show the user name based on login


  • Please log in to reply
5 replies to this topic

#1 hemlock

hemlock
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 August 2006 - 06:33 AM

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...nsitional.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>


#2 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 31 August 2006 - 10:24 AM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#3 hemlock

hemlock
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 August 2006 - 06:25 PM

Sorry I did not notice the Dreamweaver PHP Help. Thanks for moving this post to the right place.

#4 hemlock

hemlock
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 August 2006 - 06:38 PM

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


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.



#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 August 2006 - 06:40 PM

Nasty! DW code. But the session variable you'll want use is $_SESSION['MM_Username']

#6 hemlock

hemlock
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 August 2006 - 06:55 PM

I wish that I could write my code with out the help of Dreamweaver. But I still have much to learn.

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users