drsfgwuw61488 2014-11-30 11:53
浏览 32
已采纳

使用下一页中上一页的现有变量和数据库连接

In my login page I used Dreamweaver CC Server Behaviours to create login validation (name of the sql connection is user_information) and a new session. Now I want to use that username (who logged in) in my next page.

How can I do it? Database name is login.

Here is the code of login page:

<?php require_once('../Connections/user_information.php'); ?>
<?php
mysql_select_db($database_user_information, $user_information);
$query_user_login = "SELECT * FROM username";
$user_login = mysql_query($query_user_login, $user_information) or die(mysql_error());
$row_user_login = mysql_fetch_assoc($user_login);
$totalRows_user_login = mysql_num_rows($user_login);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start(); 
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck']; 
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "../q1.php";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_user_information, $user_information);

$LoginRS__query=sprintf("SELECT username, password FROM username WHERE username=%s AND       
password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

$LoginRS = mysql_query($LoginRS__query, $user_information) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
 $loginStrGroup = "";

if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;       

if (isset($_SESSION['PrevUrl']) && false) {
  $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
  • 写回答

1条回答 默认 最新

  • dongrenshi0889 2014-11-30 13:21
    关注

    Okay, so somewhere near the top of the next page, you need to include <?php session_start(); ?> and then in the place of where you want the username to be displayed, you need to put <?php echo $_SESSION['MM_Username']; ?> for example:

    <h1> Welcome to my site, <?php echo $_SESSION['MM_Username']; ?> </h1>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化