Posted By

dandyna on 09/08/06


Tagged

form login php password user


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

dandyna
vali29
willcodeforfood


Gestionale per utente php con form di login, logout, upload e canc files


 / Published in: PHP
 

admin panel for php scripts with a login form elaborated by a function.php page, then an upload form with canc option

  1. //admin.php page
  2.  
  3.  
  4. if($_SESSION['galleria']!="admin"){ ?>
  5.  
  6.  
  7. <form method="post" action="function.php">
  8. <input type="hidden" name="tipo" value="login">
  9. User <input type="text" name="user"><br />
  10. Password <input type="password" name="password">
  11. <br />
  12. <input type="submit" value="INVIA">
  13. </form>
  14.  
  15.  
  16. <? } else {?>
  17.  
  18.  
  19. <form method="post" enctype="multipart/form-data" action="function.php">
  20. <input type="hidden" name="tipo" value="upload">
  21. <input type="file" name="documento">
  22. <br />
  23. <input type="submit" value="INVIA">
  24. </form>
  25. <? }
  26. $cartella="photo";
  27. $directory=opendir($cartella);
  28.  
  29. while($files=readdir($directory))
  30. {
  31. if ($files != "." and $files !="..")
  32. print $files."<a href='function.php?tipo=canc&file=".$files."'>cancella</a><br>";
  33.  
  34.  
  35.  
  36. }
  37. /*fine sessione file manager*/ ?>
  38. <a href="function.php?tipo=logout">Logout</a>
  39.  
  40.  
  41.  
  42. //function.php page
  43.  
  44. <?
  45. session_start(); /*va sempre in cima alla pagina per dirgli che abbiamo intenzione di utilizzare all'interno del documento delle variabili di sessione*/
  46. $cartella="photo";
  47. switch($_REQUEST['tipo']) {
  48. case'login':
  49. if(($_REQUEST['user']=="yourusername")&&($_REQUEST['password']=="yourpassword")){
  50. /* creo una ariabile di sessione, che si chiamerà galleria:*/
  51. $_SESSION['galleria']="admin";
  52. }
  53. /*se non c'è la variabile di sessione facciamo ritornare l'utente alla pagina di admin*/
  54. header("location:admin.php");
  55. break;
  56. case'logout':
  57. header("location:admin.php"); /*this permits to return to previous page*/
  58. break;
  59. case'upload':
  60. move_uploaded_file( $_FILES['documento']['tmp_name'],$cartella."/".$_FILES['documento']['name']);
  61. chmod($cartella."/".$_FILES['documento']['name'],0666);
  62. header("location:admin.php"); /*this permits to return to previous page*/
  63. break;
  64. case'canc':
  65. unlink($cartella."/".$_REQUEST['file']);
  66. header("location:admin.php"); /*this permits to return to previous page*/
  67. break;
  68. }
  69. ?>

Report this snippet  

You need to login to post a comment.