Total members 11895 |It is currently Sat Dec 21, 2024 5:12 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




Author:
Newbie
User avatar Posts: 7
Have thanks: 0 time

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

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

i need to store in my database


Author:
Newbie
User avatar Posts: 7
Have thanks: 0 time

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.

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

how it will store the time in the database


Author:
Newbie
User avatar Posts: 7
Have thanks: 0 time

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();
 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 6 posts ] 

  Related Posts  to : login using sessionid or time
 develop a login page- login servlet - ServletContext     -  
 login using jsp     -  
 php login with session     -  
 login using Ajax     -  
 ASP.NET 2.0 Login Controls     -  
 Ajax Login     -  
 Login using session with php and mysql     -  
 Send login information     -  
 Cookie based login in php     -  
 code for login by jsp and ajax     -  



Topic Tags

PHP Date, PHP Database, PHP Sessions
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com