Jump to content
eyexro

Cod php

Recommended Posts

Pune htaccess+htpasswd, daca iti trebuie ceva extrem de simplu, nu are rost sa te complici. Sigur, nativ, etc..

Exemplu


# .htaccess file
AuthType Basic
AuthName "For Members Only"
AuthUserFile /calea/catre/documentroot/.htpasswd
require valid-user


# .htpasswd file
eyexro:L2stq4/Uo

Nota: .htpasswd il generezi din linia de comanda cu htpasswd sau poti folosi un tool online.

Asta e tot.

Edited by aelius
  • Downvote 1
Link to comment
Share on other sites

  • Moderators

@gecko: Nu ai ce sa faci cu sesiunile si nici de ce sa criptezi parola.

<?php
$adminpass = "secretpass123";
$adminname = 'admin';
if ($_POST['pword'] == $adminpass && $_POST['uname'] == $adminname) {
?>
<!-- codul html pentru pagina aici -->
<?php } else { ?>
<form action="" method="POST">
<input type="text" name="uname" />
<input type="password" name ="pword" />
<input type="submit" value="Login" />
</form>
<?php } ?>

Edited by Dragos
Link to comment
Share on other sites

  • Moderators
Am criptat-o în caz c? cineva preia scriptul prin alte metode, totusi s? nu fie clar?... ?i sesiunea este pentru perioada de login, dac? el intr? pe pagin? f?r? sesiune va avea acces doar o dat?, apoi când intra iar ii cere datele de login. Sesiunea l-ar ?ine minte mai mult timp.

Daca vrei sa ramana mai mult timp, pui cookie

<?php
$adminpass = "secretpass123";
$adminname = 'admin';
$h = md5($adminname . $adminpass . "sh");
if ($_POST['pword'] == $adminpass && $_POST['uname'] == $adminname)
setcookie("user",$h,time()+3600);
if($_GET['p']=="delogare")
setcookie("user","",time()-3600);
if($_COOKIE['user']==$h)
{
?>
<a href="?p=delogare">Delogare</a>
<!-- codul html pentru pagina aici -->
<?php } else { ?>
<form action="" method="POST">
<input type="text" name="uname" />
<input type="password" name ="pword" />
<input type="submit" value="Login" />
</form>
<?php } ?>

Edited by Dragos
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...