Jump to content

Display login name


cerberus478

Recommended Posts

I would like to know how to display the user's name after they logged in.

 

This is the form:

 

<form action="login" method="post" name="LoginForm">
<p>
	<input name="username" type="text" /></p>
<p>
	<input name="password" type="text" /></p>
<p>
	<input type="submit" value="Login" /></p>
</form>

 

This is the login.php

<?php
$myusername=$_POST['username']; 
$mypassword=$_POST['password'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("username");
session_register("password"); 
header("location:success");
}
else {
echo "Wrong Username or Password";
}
?>

 

This is the page that it goes to after login, success.php:

<?php
foreach ($this->_params['list'] as $login ){
$login_name = $login['name'];

echo "<table>";
echo "<tr>";
echo "<td>";
echo "<a href=/logins/view/".$login['id'].">$login_name</a>";
echo "</td>";
echo "</tr>";
echo "</table>";

}
?>
<?php

session_destroy();

?>
<a href="/partner_portals/view">Log out</a>

Link to comment
https://forums.phpfreaks.com/topic/249760-display-login-name/
Share on other sites

http://php.net/manual/en/function.session-register.php  -  Don't use this.

 

http://www.php.net/manual/en/function.session-start.php  -  Use this to start your session on any php script your require the use of sessions with.

 

Then set the sessions in this fashion:

$_SESSION['ID']		  = $username;
$_SESSION['username'] = $userID;

//add any more sessions you require here.

//now redirect to the locations required after authentication. 

Link to comment
https://forums.phpfreaks.com/topic/249760-display-login-name/#findComment-1282005
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.