Reseller Domain Murah dan termurah di Indonesia? ya di ResellerCamp.
         
 

Forum PHP Indonesia

 
Advanced Search
   
 
Home Register FAQ Memberlist Usergroups  
 
 

Forum PHP Indonesia Forum Index Session & Cookie Time saat session login
Display posts from previous:   
      All times are GMT + 7 Hours  

Time saat session login

Post new topic  Reply to topic Goto page 1, 2  Next

Wed Aug 18, 2010 07:36
Author Message
aldot
Anak Baru
Anak Baru


Joined: 18 Aug 2010
Posts: 1

Post subject: Time saat session login Reply with quote

Code:
<?php <?php 
include "../config/koneksi.php"
$pass=md5($_POST[password]); 
 
$login=mysql_query("SELECT * FROM user  
WHERE id_user='$_POST[id_user]' AND password='$pass'"
); 
$ketemu=mysql_num_rows($login); 
$r=mysql_fetch_array($login); 
 
// Apabila username dan password ditemukan (valid) 
if ($ketemu 0){ 
 
session_start(); // Untuk memulai session 
 
  // Daftarkan session ke server 
 
session_register("namauser");  
 
session_register("passuser"); 
 
  
// isi dari variabel session 
  
$_SESSION[namauser]=$r[id_user]; 
 
$_SESSION[passuser]=$r[password]; 
 
header('location:index.php'); // Buka hal input berita 

else{ 
 echo(
"<center>Login gagal ! username & password tidak benar<BR></center>"); 
 echo(
"<center><A HREF=form_login.php>Ulangi Lagi</A></center>"); 

?> ?>


nah gy mana para master jika kita ingin menggunakan batas waktu saat udah masuk ke index.php .
mohon bantuannya Cry Cry
_________________
hidup penuh cobaaan serta perjuangan :)
 
View user's profile Send private message Visit poster's website Yahoo Messenger
      Back To Top  

Fri Sep 17, 2010 07:13
Author Message
ari_galigo
PHP Programmer
PHP Programmer


Joined: 20 Nov 2009
Posts: 82

Post subject: Reply with quote

Code:
<?php function login_validate() {
        
$timeout 300;
        
$_SESSION['expires_by'] = time() + $timeout;
    }
    function 
login_check() {
        
$exp_time $_SESSION['expires_by'];
        if (
time() < $exp_time) {
            
login_validate();
            return 
true;
        } else {
            unset(
$_SESSION['expires_by']);
            return 
false;
        }
    }
if(!isset(
$_SESSION['name']))
{
    
$rs -> logout();
}
else {
    if (!
login_check() ) {
            
$rs -> logout();
        }
            else { 
?>


code html disini

Code:
<?php ?>
 
View user's profile Send private message
      Back To Top  

Mon Dec 06, 2010 20:43
Author Message
jojox
PHPnewbie
PHPnewbie


Joined: 06 Dec 2010
Posts: 10

Post subject: Reply with quote

Maaf master2, newbiew ne...
Saya coba untuk memasukan timer itu ke dalam sessionnya tapi knpa error ya?

Ne script saya (masih belajar master..^_^ ) :

<?
session_start();
require_once "cekWaktu.php"; //Koneksi dengan fungsi periksa waktu

function anti_injection($data){
$filter = mysql_real_escape_string(stripslashes(strip_tags(htmlspecialchars($data,ENT_QUOTES))));
return $filter;
}
$username = anti_injection($_POST[username]);
$password = anti_injection(md5($_POST[password]));

// pastikan username dan password adalah berupa huruf atau angka.
if (!ctype_alnum($username) OR !ctype_alnum($password)){
?>
<script language="javascript">
document.location="index.php?page=AntiSQLInjection";
</script>
<?
}
else{
$server = "localhost";
$username = "root";
$password = "";
$db_name = "db_joris";
$db = mysql_connect($server,$username,$password) or DIE("Connection
is down ");
mysql_select_db($db_name) or DIE("Database name not available !!");


$login = mysql_query("select * from guru where
(username = '" . $_POST['username'] . "') and
(password = '" . md5($_POST['password']) . "')",$db);
$ketemu = mysql_num_rows($login);
if ($ketemu == 1)
{
$_SESSION['username'] = $_POST['username'];
header("location: securepage.php");
}
else
{
header("Location: index.php?page=Salah");
}

} //Tutup Terakhir
?>

-----------------------------------
Kalo boleh tau taruh dimana ya script buat expire session itu masta?
 
View user's profile Send private message Visit poster's website Yahoo Messenger
      Back To Top  

Thu Dec 09, 2010 20:40
Author Message
rehantu
Anak Baru
Anak Baru


Joined: 09 Dec 2010
Posts: 3
Location: Bogor

Post subject: Reply with quote

coba pakai cookie...

//...sebelumnya
$username = anti_injection($_POST[username]);
$password = anti_injection(md5($_POST[password]));
setcookie($_POST[username],$user,time()+60);
//...selanjutnya

satuannya dalam detik, jadi code diatas itu waktu expire nya 1 menit.
 
View user's profile Send private message Visit poster's website
      Back To Top  

Fri Dec 10, 2010 15:24
Author Message
jojox
PHPnewbie
PHPnewbie


Joined: 06 Dec 2010
Posts: 10

Post subject: Reply with quote

Berarti masukan :
Code:
<?php setcookie($_POST[username],$user,time()+60); ?>

Dibawah :
Code:
<?php $username anti_injection($_POST[username]);
$password anti_injection(md5($_POST[password])); ?>
ya....?
 
View user's profile Send private message Visit poster's website Yahoo Messenger
      Back To Top  

Tue Dec 14, 2010 01:19
Author Message
rehantu
Anak Baru
Anak Baru


Joined: 09 Dec 2010
Posts: 3
Location: Bogor

Post subject: Reply with quote

yap...
 
View user's profile Send private message Visit poster's website
      Back To Top  

Sun Dec 19, 2010 22:16
Author Message
ari_galigo
PHP Programmer
PHP Programmer


Joined: 20 Nov 2009
Posts: 82

Post subject: Reply with quote

rehantu wrote:
coba pakai cookie...

//...sebelumnya
$username = anti_injection($_POST[username]);
$password = anti_injection(md5($_POST[password]));
setcookie($_POST[username],$user,time()+60);
//...selanjutnya

satuannya dalam detik, jadi code diatas itu waktu expire nya 1 menit.



$user dari mana di ambilnya om?
 
View user's profile Send private message
      Back To Top  

Thu Dec 30, 2010 21:02
Author Message
musicanda
PHP Master
PHP Master


Joined: 02 Jun 2010
Posts: 263
Location: Rumahnya Angeline

Post subject: Reply with quote

ari_galigo wrote:
Code:
<?php function login_validate() {
        
$timeout 300;
        
$_SESSION['expires_by'] = time() + $timeout;
    }
    function 
login_check() {
        
$exp_time $_SESSION['expires_by'];
        if (
time() < $exp_time) {
            
login_validate();
            return 
true;
        } else {
            unset(
$_SESSION['expires_by']);
            return 
false;
        }
    }
if(!isset(
$_SESSION['name']))
{
    
$rs -> logout();
}
else {
    if (!
login_check() ) {
            
$rs -> logout();
        }
            else { 
?>


code html disini

Code:
<?php ?>




thanks bro, aku dah coba dan berhasil Big Smile
 
View user's profile Send private message Send e-mail Visit poster's website
      Back To Top  

Wed Jan 05, 2011 17:03
Author Message
whois
PHPuser
PHPuser


Joined: 31 Dec 2010
Posts: 40

Post subject: Reply with quote

5 menit sekali y gan di session end nya, apa g ribet?
_________________
www.whoisdomain.net
 
View user's profile Send private message Visit poster's website
      Back To Top  

Thu Jun 09, 2011 15:33
Author Message
helem
PHPnewbie
PHPnewbie


Joined: 28 Apr 2011
Posts: 18
Location: depok

Post subject: Reply with quote

whois wrote:
5 menit sekali y gan di session end nya, apa g ribet?


Namanya juga lagi test atau belajar gan, jadi jangan lam-lam timeny. Kan ga lucu 1x coba session nunggu sampe stgh jam Salute!
 
View user's profile Send private message
      Back To Top  

Thu Jun 16, 2011 21:41
Author Message
IzuL
PHPnewbie
PHPnewbie


Joined: 25 Mar 2008
Posts: 19
Location: Bekasi Barat

Post subject: Reply with quote

nih gw kasih lengkapnya. biar yg masup sini gak bingung bacanya.

ini formnya login.php
Code:
<?php //ini adalah awal file HTML
<html>
<
head><title>Login Page …!</title></head>
<
body>

<
form action=index.php method=POST>
<
table
border
=0
bcolor
=#DFDFDF><tr><td>username</td><td><input
type=text name=username></td></tr>
<
tr><td>password</td><td><input type=password name=password></td></tr>
<
tr><td></td><td><input type=submit name=submit value=submit></td></tr>
</
table>
</
form>

</
body>
</
html>
//ini adalah akhir file HTML ?>


jika ditekan tombolnya, maka akan mengarah kemari
index.php

Code:
<?php require_once “functions.php”;
if (( 
$_POST['username'] == ‘admin’ ) && ( $_POST['password'] == ‘admin’))
{
$_SESSION['user'] = $_POST['username'];
login_validate();
header(“locationadmin.php”);
}

else if ( empty(
$_POST['username']) && empty($_POST['password']) )
{
header(“locationlogin.php”);
?>


khan di-index.php ada fungsi login_validate() tuh..
nah itu berasal dari sini

Code:
<?php session_start();

function 
login_validate() {
$timeout 30;
$_SESSION["expires_by"] = time() + $timeout;
}

function 
login_check() {
$exp_time $_SESSION["expires_by"];
if (
time() < $exp_time) {
login_validate();
return 
true;
} else {
unset(
$_SESSION["expires_by"]);
return 
false;
}
?>


nah ini Admin.php nya
Code:
<?php require_once “functions.php”;

if (ISSET(
$_SESSION['user']))
{
if (!
login_check()) {
header(“Locationlogout.php”);
exit(
0);
}
else {
echo 
“Jika tidak ada kegiatan sama sekalianda akan logout secara otomatis … “;
}
}

else
{
echo 
“Anda tidak berhak untuk ngapa-ngapain … !! big grin“;
?>


untuk sisi sekuritinya, kyk anti injection, strip tags, trim, dll bisa liat di bagian atas...
CMIIW
 
View user's profile Send private message Send e-mail
      Back To Top  

Thu Jul 07, 2011 17:44
Author Message
TUKANG BECA BERAKSI
PHPnewbie
PHPnewbie


Joined: 06 Jul 2011
Posts: 7

Post subject: Reply with quote

agan izul dari file index.php function.php nya mana?
Code:
<?php <?php require_once “functions.php”?>
 
View user's profile Send private message
      Back To Top  

Fri Aug 05, 2011 08:05
Author Message
om daniel
PHPnewbie
PHPnewbie


Joined: 01 Aug 2011
Posts: 9

Post subject: Reply with quote

gan klo misalanya ...

waktu login di batasi sampe 1jam lalu untuk bisa akses loginnya dimulai pada hari ke esoknya .. tuh cara nya mesti gmn yah om

apakah ada contoh skripnya kah ...?? tolong yah om

thanx Big Smile
 
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
      Back To Top  

Fri Aug 05, 2011 13:12
Author Message
Adhitia Ginanjar
PHP Programmer
PHP Programmer


Joined: 29 Jul 2011
Posts: 120
Location: Bandung

Post subject: Reply with quote

Wew pada panjang.
Kata ane ma enak gni:

Code:
<?php session_start();
    if (empty(
$_SESSION[username]) AND empty($_SESSION[passuser]))
    {
      echo 
"
      <center>For access this modul, You must LOGIN first!<br>"
;
      echo 
"<a href=index.php><b>LOGIN</b></a></center>";
    }
    else
    {
    
    
// periode timeout
    
$inactive 1800// 30 menit dalam detik

    
if(isset($_SESSION['timeout']) ) 
    {
        
$nyawa time() - $_SESSION['timeout'];
        
        if(
$nyawa $inactive)
        { 
            
session_destroy(); header("Location: index.php"); 
        }
    }
    
    
$_SESSION['timeout'] = time(); ?>

//disini file indexnya

<?
?>


Gitu kk Big Smile
_________________
TAKE nothing but PICTURES
LEAVE nothing but FOOTPRINTS
KILL nothing but TIME
 
View user's profile Send private message
      Back To Top  

Fri Aug 05, 2011 13:12
Author Message
Adhitia Ginanjar
PHP Programmer
PHP Programmer


Joined: 29 Jul 2011
Posts: 120
Location: Bandung

Post subject: Reply with quote

Wew pada panjang.
Kata ane ma enak gni:

Code:
<?php session_start();
    if (empty(
$_SESSION[username]) AND empty($_SESSION[passuser]))
    {
      echo 
"
      <center>For access this modul, You must LOGIN first!<br>"
;
      echo 
"<a href=index.php><b>LOGIN</b></a></center>";
    }
    else
    {
    
    
// periode timeout
    
$inactive 1800// 30 menit dalam detik

    
if(isset($_SESSION['timeout']) ) 
    {
        
$nyawa time() - $_SESSION['timeout'];
        
        if(
$nyawa $inactive)
        { 
            
session_destroy(); header("Location: index.php"); 
        }
    }
    
    
$_SESSION['timeout'] = time(); ?>

//disini file indexnya

<?
?>


Gitu kk Big Smile
_________________
TAKE nothing but PICTURES
LEAVE nothing but FOOTPRINTS
KILL nothing but TIME
 
View user's profile Send private message
      Back To Top  
Post new topic  Reply to topic Goto page 1, 2  Next

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


      Back To Top  

Page 1 of 2
Goto page 1, 2  Next
Jump to:  
Powered by phpBB © 2001, 2002 phpBB Group
Toko Kaos Couple | Avalanche style by What Is Real © 2004 | Toko Baju Butik Online | Cara Pedia | Busana Baju Muslim