Jump to content

[SOLVED] Logged in as


zero_ZX

Recommended Posts

Hi there.

I'm in a big trouble. i've searched at google and aswell as this site (it gaves 40 pages, and after checking 5 i deicded to open a topic)

I'm sure it has been asked for but any ways:

 

I'm very new at php and im trying to learn. Right now i've downloaded and edited a nice little login script, and i've already edit it alot.

Now what i need is to make the page display "you are now logged in as %username%".

Can any one help me at that one?

Link to comment
https://forums.phpfreaks.com/topic/108533-solved-logged-in-as/
Share on other sites

if you are moving to a new page were you want this to be displayed then you would have to use something like

 

You are now logged in as <?php echo $_POST["username"]; ?>

 

depending on how you are posting your information across from the login page.  it would be nice to see that code

Link to comment
https://forums.phpfreaks.com/topic/108533-solved-logged-in-as/#findComment-556521
Share on other sites

My login page/code

(there are also some html, i hope it doesnt annoy you too much)

<?php require_once('Connections/modulatemedia.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?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=md5($_POST['password']);
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "admin.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_modulatemedia, $modulatemedia);
  
  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $modulatemedia) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //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 );
  }
}
?>
<style type="text/css">
body {
background-color: #000000;
background-image: url(nsa.jpg);
background-repeat: no-repeat;
}

#container {
background-image:url(nsa.jpg);
margin-left:auto;
margin-right:auto;
height: 400px;
width: 500px;
text-align:center;
}
.style1 {
color: #663300;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
.style3 {color: #330000}
.style5 {
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
</style></head>

<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>


<form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
  <label></label>

     
      </span>      <div align="right" class="style3">
        <div align="left"><strong>Username:</strong></div>
      </div>      
      </td>
      <td width="152"><input name="username" type="text" id="username" tabindex="1" maxlength="20" /></td>
    </tr>
    <tr>
      
      </span>     <div align="right" class="style3">
        <div align="left"><strong>Password:</strong></div>
      </div>      
      </td>
      <td><input name="password" type="password" id="password" tabindex="2" maxlength="20" /></td>
    </tr>

    <tr>
      <td> </td>
      <td><input name="submit" type="submit" id="submit" tabindex="4" onclick="MM_validateForm('username','','R');MM_validateForm('password','','R');MM_validateForm('email','','RisEmail');return document.MM_returnValue" value="Login" /></td>
    </tr>
    <tr>
    </tr>
  
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/108533-solved-logged-in-as/#findComment-556532
Share on other sites

if you are moving to a new page were you want this to be displayed then you would have to use something like

 

You are now logged in as <?php echo $_POST["username"]; ?>

 

depending on how you are posting your information across from the login page.  it would be nice to see that code

 

 

^^^ do that ^^^^

Link to comment
https://forums.phpfreaks.com/topic/108533-solved-logged-in-as/#findComment-556534
Share on other sites

//declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	 

 

Find that

 

and add:

 

$_SESSION['MM_Password'] = $password;

 

On every page, the md5 psw hash will be stored as $_SESSION['MM_Password']

Link to comment
https://forums.phpfreaks.com/topic/108533-solved-logged-in-as/#findComment-556563
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.