|
| |
|
|
All times are GMT + 7 Hours
|
|
Time saat session login
 |
Wed Aug 18, 2010 07:36 |
 |
Author |
Message |
aldot Anak Baru

Joined: 18 Aug 2010 Posts: 1
|
| Post subject: Time saat session login |
|
|
| 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  _________________ hidup penuh cobaaan serta perjuangan :) |
|
| |
|
|
 |
Fri Sep 17, 2010 07:13 |
 |
Author |
Message |
ari_galigo PHP Programmer

Joined: 20 Nov 2009 Posts: 82
|
| Post subject: |
|
|
| 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
|
|
| |
|
|
 |
Mon Dec 06, 2010 20:43 |
 |
Author |
Message |
jojox PHPnewbie

Joined: 06 Dec 2010 Posts: 10
|
| Post subject: |
|
|
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? |
|
| |
|
|
 |
Thu Dec 09, 2010 20:40 |
 |
Author |
Message |
rehantu Anak Baru

Joined: 09 Dec 2010 Posts: 3 Location: Bogor
|
| Post subject: |
|
|
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. |
|
| |
|
|
 |
Fri Dec 10, 2010 15:24 |
 |
Author |
Message |
jojox PHPnewbie

Joined: 06 Dec 2010 Posts: 10
|
| Post subject: |
|
|
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....? |
|
| |
|
|
 |
Tue Dec 14, 2010 01:19 |
 |
Author |
Message |
rehantu Anak Baru

Joined: 09 Dec 2010 Posts: 3 Location: Bogor
|
| Post subject: |
|
|
| yap... |
|
| |
|
|
 |
Sun Dec 19, 2010 22:16 |
 |
Author |
Message |
ari_galigo PHP Programmer

Joined: 20 Nov 2009 Posts: 82
|
| Post subject: |
|
|
| 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? |
|
| |
|
|
 |
Thu Dec 30, 2010 21:02 |
 |
Author |
Message |
musicanda PHP Master


Joined: 02 Jun 2010 Posts: 263 Location: Rumahnya Angeline
|
| Post subject: |
|
|
| 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
|
thanks bro, aku dah coba dan berhasil  |
|
| |
|
|
 |
Wed Jan 05, 2011 17:03 |
 |
Author |
Message |
whois PHPuser

Joined: 31 Dec 2010 Posts: 40
|
| Post subject: |
|
|
5 menit sekali y gan di session end nya, apa g ribet? _________________ www.whoisdomain.net |
|
| |
|
|
 |
Thu Jun 09, 2011 15:33 |
 |
Author |
Message |
helem PHPnewbie

Joined: 28 Apr 2011 Posts: 18 Location: depok
|
| Post subject: |
|
|
| 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  |
|
| |
|
|
 |
Thu Jun 16, 2011 21:41 |
 |
Author |
Message |
IzuL PHPnewbie

Joined: 25 Mar 2008 Posts: 19 Location: Bekasi Barat
|
| Post subject: |
|
|
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(“location: admin.php”);
}
else if ( empty($_POST['username']) && empty($_POST['password']) )
{
header(“location: login.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(“Location: logout.php”);
exit(0);
}
else {
echo “Jika tidak ada kegiatan sama sekali, anda 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 |
|
| |
|
|
 |
Thu Jul 07, 2011 17:44 |
 |
Author |
Message |
TUKANG BECA BERAKSI PHPnewbie

Joined: 06 Jul 2011 Posts: 7
|
| Post subject: |
|
|
agan izul dari file index.php function.php nya mana?
| Code: | <?php <?php require_once “functions.php”; ?> |
|
|
| |
|
|
 |
Fri Aug 05, 2011 08:05 |
 |
Author |
Message |
om daniel PHPnewbie

Joined: 01 Aug 2011 Posts: 9
|
| Post subject: |
|
|
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  |
|
| |
|
|
 |
Fri Aug 05, 2011 13:12 |
 |
Author |
Message |
Adhitia Ginanjar PHP Programmer


Joined: 29 Jul 2011 Posts: 120 Location: Bandung
|
| Post subject: |
|
|
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  _________________ TAKE nothing but PICTURES
LEAVE nothing but FOOTPRINTS
KILL nothing but TIME |
|
| |
|
|
 |
Fri Aug 05, 2011 13:12 |
 |
Author |
Message |
Adhitia Ginanjar PHP Programmer


Joined: 29 Jul 2011 Posts: 120 Location: Bandung
|
| Post subject: |
|
|
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  _________________ TAKE nothing but PICTURES
LEAVE nothing but FOOTPRINTS
KILL nothing but TIME |
|
| |
|
|
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
|
|
Page 1 of 2 Goto page 1, 2 Next |
|
|
|