/    Sign up×
Community /Pin to ProfileBookmark

Display User’s name after login

I’ve create a login page in dreamweaver that works great. I have a database of users with username, password & real name.

After you login, I want to have a personalized greeting on the success page “welcome [realName]”….. How can I do this? It should be simple but I’m new to PHP and am having trouble with this.

The code is below.

[code=php]<?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 = “logout.php”;
if ($logoutGoTo) {
header(“Location: $logoutGoTo”);
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = “user,admin”;
$MM_donotCheckaccess = “false”;

// *** 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 == “”) && false) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = “failed.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″ />
<meta name=”verify-v1″ content=”L2jBm4mzGHu456H15YJEMHfNinTiiWaUDraquGYQWY4=” />
<title>EBN: Sales Ordering System</title>
<style type=”text/css”>
@import url(“page.css”);
</style>
<body>
<div id=”holder”>
<div id=”welcome”><span class=”welcomeHead”>Welome to this site.</span><br />
<br />
more test.</div>
</div>
</body>
</html>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleApr 02.2008 — [code=php]
<div id="welcome"><span class="welcomeHead">Welome, <?= $_SESSION['MM_Username'] ?>.</span><br />

[/code]
Copy linkTweet thisAlerts:
@JayCallyauthorApr 02.2008 — Dude, that was it!? I new it would be something easy. Thanks a lot. In the database, there is also real name and email. Could I display those in a similar way?
Copy linkTweet thisAlerts:
@jasonahouleApr 02.2008 — Yes... I think. It depends on what you mean.
Copy linkTweet thisAlerts:
@JayCallyauthorApr 03.2008 — I have a database that as user info. Each user has an ID number, password, username, real name and email. They login with the username and password. Instead of using the username on the welcome page, I'd like to use the real name. I'd also like to dynamically add the email address to a hidden field in a form.

Example. Bob92 logs in, page says "welcome Bob Smith", fills out form and sends it. His email is placed in a hidden field in form. I receive email from [email][email protected][/email]

That is what I am trying to do. I'm still new to PHP and am trying to figure out how to do this. I've searched all over and gone through book after book. Any ideas?
×

Success!

Help @JayCally spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...