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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决