Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have created a login script in php where user can register and then login to access the private page. Logged in users can see their username on private page-"welcome:username" . All working fine. Problem is i want to display welcome back:username message on private page when users logged in again. I have tried google but no success. Please help, whats the logic behind it?
Posted

I think you can try to add a column in your SQL table where the value change when the user first login (example TRUE or FALSE / 1 or 0 value from column Login)...

You can look this pic http://s13.postimg.org/yuquyht1j/Capture.png[^]

So the logic is you must INSERT value 1 in "login" column when user first login and your auth func must check whether the value of "login" column is 1 or 0...

I think this is the simplest trick...
 
Share this answer
 
Comments
Pankaj Mahor 24-Aug-13 12:23pm    
I have already tried it but whenever i click login button, private page shows welcome:username.
I have an alternative easy method to it without using database.
The user is login with his/her user name isn't?.
So read username from form,

if(isset($_REQUEST['username') && isset($_REQUEST['password']))
{
$username = $_REQUEST['username];
$password = $_REQUEST['password'];
$login = loginFunction($username, $password);
if($login)
{
echo "Welocome back $username";
}
}
 
Share this answer
 
Add a column to your database that stores numeric value(number of times a particular user has logged in to your site) for a logged in user.When a user first logs in set that value to 1.On each consecutive logging you have to increment the value by one and update the value by Update command of sql .This way you can have a track of a particular user that used your system.If the number is more than 1 obviously user is using your system again.this time populate the user with a message "Welcome back:Username".Hope this helps you.Thank s in advance.
 
Share this answer
 
Can you post your code where you define the check func here??
 
Share this answer
 
Comments
Pankaj Mahor 24-Aug-13 13:01pm    
ok, here is my config.php(private page)-

?php
session_start(); //Start Session
// username and password sent from form

$myusername=$_POST["textbox1"];
$mypassword=$_POST["textbox2"];
$remember =$_POST["remm"];
//$dt=date("y/m/d h:i:s");


// Connecting Database

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="dbsite"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");
$sql="select *from $tbl_name 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) // we can use $count>0 also.
{
$_SESSION['myvaruser']=$myusername;
$_SESSION['myvarpass']=$mypassword;
//$_SESSION['mydt']=$dt;
//$myquery="update users set datetime=now() where username='$_SESSION[myvaruser]' and password='$_SESSION[myvarpass]'";
//mysql_query($myquery);

header("Location:home.php");
if(isset($remember))
{
setcookie ('cookuser',$myusername, time()+60*60*24*30,"/");
setcookie ('cookpass',$mypassword, time()+60*60*24*30,"/");

//$setone="update users set checkcookie='1' where username='$_SESSION[myvaruser]' and password='$_SESSION[myvarpass]'";
//mysql_query($setone);
}

}
else
{
echo "Wrong Username or Password";
}

?>


And home.php-




<!DOCTYPE HTML>

<html>
<head><title>Hi</title>
</head>
<body bgcolor="gray">Logout

Welcome To Home!






<form style="position:absolute; top:100px;"method="post" action="settings.php">
<input type="text" name="txt" value=""/>
<input type="submit" name="sub" value="click"/>
</form>
<br>
<br>

</body>
</html>
Pankaj Mahor 24-Aug-13 13:50pm    
Please reply.
Taftazani 26-Aug-13 3:07am    
Sorry but i don't see a function where you can detemine whether its the user first log in or not. (or maybe I'm not read it well)

So here is the example code based on my table in earlier post..
//for check first login or not
if ($count > 0){
session_start();

$_SESSION[user] = $r[username];
$_SESSION[psss] = $r[pass];
$_SESSION[leveluser] = $r[lvl];
$_SESSION[login] = $r[login];
}

//to show Welcome or Welcome Back
if($_SESSION[login] == 1) {
echo '

WELCOME

';
}
else {
echo '

WELCOME BACK

';
}

Hope this will help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900