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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.