0

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 );
}
}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
3Demon
  • 550
  • 3
  • 9
  • Do you have any code that we can look at? I don't think many people here use Dreamweaver for PHP development – Adi Bradfield Nov 30 '14 at 12:36
  • question edited .. php code for the login page is there now .. now i want to use the username user entered in the next page.. – 3Demon Nov 30 '14 at 13:03
  • I've answered your question, but one thing I should point out is that mysql functions have been deprecated (for quite a while now). Everyone should be using mysqli instead, although I have no idea if Dreamweaver offers this – Adi Bradfield Nov 30 '14 at 13:23
  • yep, but i used this error_reporting(0); but next time when i work on a project i will go with Mysqli... :-) – 3Demon Nov 30 '14 at 13:52
  • You'll find your questions are easier to read if you embold things less (after too much emboldening it gets more dfficult to read). – halfer Dec 02 '14 at 17:31

1 Answers1

0

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>
Adi Bradfield
  • 2,063
  • 1
  • 17
  • 27
  • actually i wish to use this username for to extract a field from the same database in which it is lying.. for that can i use this query ("SELECT level FROM username WHERE username = 'MM_Username') or is there some other we do this? Also is our database connectivity maintained in the next page automatically? – 3Demon Nov 30 '14 at 13:49
  • you would need to adjust that query slightly to `("SELECT level FROM username WHERE username = '" . $_SESSION['MM_Username.] . "')`. And no, you would need to open another mysql connection – Adi Bradfield Nov 30 '14 at 13:56