将欢迎消息从全名更改为用户名(PHP)
我对web开发和PHP非常陌生。我正在创建一个带有会员区的网站,并希望显示欢迎“用户名”消息。在我的实际代码中,有一条显示用户全名的欢迎消息。有人能帮我吗?下面我将粘贴用于login.php和login-home.php(成员区)的代码。多谢各位将欢迎消息从全名更改为用户名(PHP),php,mysql,Php,Mysql,我对web开发和PHP非常陌生。我正在创建一个带有会员区的网站,并希望显示欢迎“用户名”消息。在我的实际代码中,有一条显示用户全名的欢迎消息。有人能帮我吗?下面我将粘贴用于login.php和login-home.php(成员区)的代码。多谢各位 login.php <?PHP require_once("./include/membersite_config.php"); if(isset($_POST['submitted'])) { if($fgmembersite->
login.php
<?PHP
require_once("./include/membersite_config.php");
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL("login-home.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Login</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
</head>
<body>
<!-- Form Code Start -->
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<form id='login' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Orcaly</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='username' ></label><br/>
<input type='text' placeholder="UserName"name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
<span id='login_username_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='password' ></label><br/>
<input type='password' placeholder="Password" name='password' id='password' maxlength="50" /><br/>
<span id='login_password_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
<div class='short_explanation'><a href='reset-pwd-req.php'>Forgot Password?</a></div>
<div class='register'><a href='register.php'>Register</a></div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("login");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("username","req","Please provide your username");
frmvalidator.addValidation("password","req","Please provide the password");
// ]]>
</script>
</div>
</div>
<!--
Form Code End (see html-form-guide.com for more info.)
-->
</body>
</html>
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Home page</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<fieldset>
<legend>Home Page</legend>
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
<div class='confirmation'><a href='change-pwd.php'>Change password</a></div>
<div class='register'><a href='access-controlled.php'>A sample 'members-only' page</a></div>
<br>
<div class='register'><a href='logout.php'>Logout</a></div>
</fieldset>
</div>
</div>
</body>
</html>
登录
主页
主页
欢迎回来!
简单的答案是您需要更改这行代码:
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
欢迎回来!
因此,$fgmembersite->UserFullName();成为保存用户名的变量或返回用户名的函数。现在,它是一个返回用户全名的函数
这可能有点超出了您目前的编程技能。一件非常简单可行的事情是在用户登录时将用户名存储为会话变量。然后可以替换$fgmembersite->UserFullName();使用$_SESSION[“username”]或任何您指定的名称
或者,您可以定义自己的函数来返回用户名,或者如果用户名由于某种原因不可用,则可以定义其他值(这是一种更好的设计)。在my fg_membersite.php中,
$fgmembersite
?的数据结构是什么?$\u SESSION中的$fgmberSite
php:function UserFullName(){return isset($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\