2012-01-10 2 views
0

이 간단한 스크립트에는 데이터베이스가 필요하지 않으므로 사용자 이름과 비밀번호가 스크립트에 정의됩니다.
각 사용자 이름과 암호의 날짜를 정의하는 스크립트를 작성하여 날짜가 만료 된 후에 해당 자격 증명을 사용하여 로그인하는 기능도 만료되도록하려면 어떻게해야합니까? 이처럼PHP 스크립트 로그인 제한 시간 생성

:

$LOGIN_INFORMATION = array( 
'you' => 'yourpassword' => '12-03-2012' 
'username2' => 'yourpassword2' => '12-05-2012' 
); 

스크립트 데모 : http://demos.savasplace.com/password/

<?php 
################################################################## 
##   Sava's Place.com Password Protect     ## 
##  Visit http://savasplace.com for more scripts   ## 
################################################################## 
$LOGIN_INFORMATION = array(
    'sava' => 'sava', 
    'you' => 'yourpassword' 
); 

// Require username or not 
// If you want to use username and password login leave this true. 
// If you want only to request a password set it for false. 

define('USE_USERNAME', true); 

// To password protect your pages you need to include this file in them 
// To get the correct code for inclusion open password.php?code in your broswer 

if(isset($_GET['code'])) { 
    die('<center><font face="Verdana" size="2">Include following code into every page you would like to protect, at the very beginning (first line):<br><br><strong>&lt;?php include("' . __FILE__ . '"); ?&gt;</strong></center></font>'); 
} 
if(isset($_GET['logout'])) { 
    setcookie("verify", ''); // clear password; 
    die('<center><font face="Verdana" size="2">Logged out.</font></center>'); 
} 
if(!function_exists('showLoginPasswordProtect')) { 
function showLoginPasswordProtect($error_msg) { 
?> 
<!-- And this is the output --> 

<html> 
<head> 
<title>Login to access this page</title> 
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<style> 
* { 
font-family:Verdana; 
font-size:12px; 
} 
a { 
color: #000000; 
text-decoration: none; 
} 

a:hover { 
color: red; 
text-decoration: none; 
} 

input { 
border: 1px solid black; 
background-color: #FFFFFF; 
} 
.bodyform { 
border-color: #000000; 
border-style:solid; 
border-width: 3px; 
width:400px; 
} 
.title { 
color: #FFFFFF; 
background: #000000; 
padding: 5px; 

} 
</style> 
</head> 
<body> 
<center><br /><br /> 
<div class="bodyform" align="center"> 
<form method="post"> 
<div class="title"> 
<strong>Access restricted - Login Below:</strong> 
</div> 
<div style="padding-right:10px;padding-left:10px;"> 
<font color="red"><strong><?php echo $error_msg; ?><strong></font><br /><br /> 
<?php if (USE_USERNAME) echo '<table> 
<tr> 
<td align="left">Login:</td> 
<td align="right"><input type="input" name="access_login" /></td> 
</tr> 
<tr> 
<td>Password:</td>'; ?> 
<td><input type="password" name="access_password" /></td> 
</tr> 
</table> 
<p></p> 
<input type="submit" name="Submit" value="Submit" /> 
</form> 
</div> 
</div> 
<br /> 
Powered by <a href="http://savasplace.com" target="_blank">Sava's Place Password Protect Script</a> 
</center> 
</body> 
</html> 
<?php 
    die(); 
} 
} 
if (isset($_POST['access_password'])) { 
    $login = isset($_POST['access_login']) ? $_POST['access_login'] : ''; 
    $pass = $_POST['access_password']; 
    if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION) 
    || (USE_USERNAME && (!array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass)) 
) { 
    showLoginPasswordProtect("Incorrect password."); 
    } 
    else { 
    setcookie("verify", md5($pass)); 
    unset($_POST['access_login']); 
    unset($_POST['access_password']); 
    unset($_POST['Submit']); 
    } 

} 
else { 
    if (!isset($_COOKIE['verify'])) { 
    showLoginPasswordProtect(""); 
    } 
    $found = false; 
    foreach($LOGIN_INFORMATION as $kay=>$val) { 
    if ($_COOKIE['verify'] == md5($val)) { 
     $found = true; 
     break; 
    } 
    } 
    if (!$found) { 
    showLoginPasswordProtect(""); 
    } 
} 
?> 
+4

''태그? 진심으로? ** 년 동안 사용되지 않습니다 **! – ThiefMaster

답변

0

당신은 또한 변환 현재 데이터를 시간을 숫자 값으로 날짜를 변환하고 당신에게 그것을 비교하는 strtotime을 사용할 수 있습니다 숫자 값이고 지정한 값보다 큰 경우 로그인시 false를 반환합니다.

$LOGIN_INFORMATION = array( 
    'you' => array('pass' => 'yourpassword', 'date' => '12-03-2012'), 
    'username2' => array('pass' => 'yourpassword2', 'date' => '12-05-2012') 
); 


if(strtotime($LOGIN_INFORMATION['you']['date']) > time()) 
{ 
    exit(); 
    // show error message or anything 
} 
else 
{ 
    // login or whatever you would like to happen here in case the date did not expired 
    // check password, etc 
} 

php function strtotime

php function time

+0

**이 스크립트에 ** 명령어 **가 포함되어 있다면 ** strtotime을 포함시킬 수 있습니까? 이 명령을 입력해야하는 부분은 무엇입니까? – Amirreza

+0

@Amirreza 당신이 처음에 당신의 .php 파일에 위의 코드 샘플을 작성했거나, 실제 로그인을하고있는 곳이 어디인지는 알고 있습니다. 아마도'$ pass = $ _POST [ 'access_password']; 뒤에 그것을 놓는 것이 가장 좋습니다. '무엇을 알고 있습니까? 어쩌면 당신이 적어도 당신을 괴롭히는 행동을 관리하려고 노력할 수도 있습니다. – khael

+0

어떻게이 코드를 편집하여 메인 스크립트에 넣을 수 있습니까? ** if (strtotime ($ LOGIN_INFORMATION [ '당신'] [ '날짜'])> 시간()) ** – Amirreza

0

당신은에 setcookie을 변경할 수 있습니다 :

setcookie("verify", md5($pass), time()+3600);

다음 쿠키 1 시간 후에 만료 것이며, 사용자는 더 이상에 기록 될 것이다 쿠키/로그인이 오래 지속되기를 원한다면 exp ire 매개 변수를 길게 설정하십시오.