Switch to full style
Dynamic open source server-side web development
Post a reply

login using sessionid or time

Tue Sep 20, 2011 7:55 am

Save the login date to database with session id:
i have written a code in php using sessions.below is the code......

Code:

<?php
if(!isset($_SESSION)) 
{
 session_start();
}
$now = time();
$limit = $now;
if(isset(
$_SESSION['last_activity']) && ($_SESSION['last_activity'] < $limit)) 
{
 $_SESSION = array();
 header('Location:logout.php');
 exit;
}
 
else 
{
//the current time
$_SESSION['last_activity'] = $now;
}
?>
.
tell me how to modify in the above code that if the user is entering for first
time then using time() or sessionid it should be stored
or else if he is entering for first time then using current time() or sessionid
it must be stored.....



Re: login using sessionid or time

Thu Sep 22, 2011 11:14 am

you want to save first time login date ! , you have to save such information in database or text file which i don't recommend.

Re: login using sessionid or time

Thu Sep 22, 2011 11:17 am

i need to store in my database

Re: login using sessionid or time

Thu Sep 22, 2011 11:59 am

Code:

<?php
  $hostname
="localhost";
  
$username="username";
  
$password="password";
 
  
$dbconnectionmysql_connect ($hostname$username$password);
 
  if (!
$dbconnection) {
     die (
" cannot connect to database");
  }
 
  
$result=mysql_select_db ("databasename");
 
  if (! 
$result) {
     die (
"database could not be selected");
  }
     
  echo 
"Database ready.";
?>


Code:

  $query_res 
mysql_query"SELECT * from tableName" );
 


you may create a data column in users table , if its first time , store the time , any new visits check this column value , it null so its new visit , else it is not and do nothing.

Re: login using sessionid or time

Thu Sep 22, 2011 12:37 pm

how it will store the time in the database

Re: login using sessionid or time

Fri Sep 23, 2011 1:32 am

It is easy like other PHP variables :
Code:

         $date 
= date("Y-m-d H:i:s"); 
         $query 
=" INSERT INTO `user` VALUES (0,null,'$country_code','$username','$firstname','$lastname','$password','
$address1',
'$address2','$telephone','$mobile','$email','$city',0,'$date','$date','$date_birthday','$gender',0,'$activationkey',0)"
;
         $result =mysql_query($query );
         echo mysql_error();
 


Post a reply
  Related Posts  to : login using sessionid or time
 develop a login page- login servlet - ServletContext     -  
 login using jsp     -  
 Ajax Login     -  
 php login with session     -  
 login using Ajax     -  
 ASP.NET 2.0 Login Controls     -  
 code for login by jsp and ajax     -  
 How to Show a message before the login ?     -  
 Login using jsp,Servlets and Database following MVC     -  
 Login using session with php and mysql     -  

Topic Tags

PHP Sessions, PHP Date, PHP Database