Guest User

Untitled

a guest
May 30th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.32 KB | None | 0 0
  1. index.php
  2.  
  3. <?php
  4. session_start();
  5. ?>
  6. <html>
  7.     <head>
  8.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9.         <title>PenPalling.it</title>
  10.     </head>
  11.     <body style="background-color: lightcyan">
  12.         <table style="width: 100%">
  13.             <tbody>
  14.                 <tr>
  15.                     <td style="width: 25%">
  16.                         <?php include "menu/menu.php" ?>
  17.                     </td>
  18.                     <td>
  19.                         <?php echo 'Testo centrale (News, articoli vari)' ?>
  20.                     </td>
  21.                     <td style="width: 25%">
  22.                         <?php include "user/login.php" ?>
  23.                         <table>
  24.                             <tr>
  25.                                 <td style="width: 50%">ads google 1</td>
  26.                                 <td style="width: 50%">qualcosa da scrivere qui o lasciamo vuoto? XD</td>
  27.                             </tr>
  28.                         </table>
  29.                     </td>
  30.                 </tr>
  31.             </tbody>
  32.         </table>
  33.         <div style="text-align: center">
  34.             <p>Copyright, link a termini e condizioni, contatti(?), varie di fine pagina</p>
  35.         </div>
  36.     </body>
  37. </html>
  38.  
  39. ###########################################################################################
  40. ###########################################################################################
  41. ###########################################################################################
  42.  
  43. chklg.php
  44.  
  45. <?php
  46. ob_start();
  47. include_once '../include/config.php';
  48.  
  49.  
  50. $db = mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die('Impossibile stabilire una connessione');
  51. mysql_select_db($_CONFIG['dbname'], $db) or die('Impossibile stabilire una connessione');
  52. //Imposto le variabili per controllare gli accessi
  53. $UName = $_POST['txtUname'];
  54. $Pwd = $_POST['txtPwrd'];
  55.  
  56. //Soluzione anti SQLInjection
  57. $UName = stripslashes($UName);
  58. $Pwd = stripslashes($Pwd);
  59. $UName = mysql_real_escape_string($UName);
  60. $Pwd = mysql_real_escape_string($Pwd);
  61.  
  62. //Query SQL per controllare dati su DB
  63. $sql= "SELECT * FROM ".$_Config['User']." WHERE username='$UName' and password = md5('$Pwd')";
  64. $result=mysql_query($sql);
  65.  
  66. //Conto quanti risultati ci sono
  67. $count = mysql_num_rows($result);
  68.  
  69. //Se c'รจ un solo risultato, il login ha successo
  70. if ($count == 1){
  71.     //Imposto altre variabili di sessione
  72.     $_SESSION['Login'] = "true";
  73.     $_SESSION['UserLogin'] = $UName;
  74.  
  75.     header("location: ../index.php");
  76. }
  77.  
  78. else {
  79.     $_SESSION['Login'] = "false";
  80.  
  81.     header("location: ../index.php");
  82. }
  83.  
  84. ob_end_flush();
  85. ?>
  86.  
  87. ###########################################################################################
  88. ###########################################################################################
  89. ###########################################################################################
  90.  
  91. login.php
  92.  
  93. <?php
  94. echo $_SESSION['Login'];
  95. if(!isset($_SESSION['Login'])){
  96.     ?>
  97. <form name="frmLogin" method="post" action="user/chklg.php">
  98.     <table>
  99.         <tr>
  100.             <td>
  101.                 Username
  102.             </td>
  103.             <td>
  104.                 <input type="text" name="txtUname" />
  105.             </td>
  106.         </tr>
  107.         <tr>
  108.             <td>
  109.                 Password
  110.             </td>
  111.             <td>
  112.                 <input type="password" name="txtPwrd" />
  113.             </td>
  114.         </tr>
  115.         <tr>
  116.             <td><input type="submit" name="btnInvio" /></td>
  117.         </tr>
  118.     </table>
  119. </form>
  120. <?php
  121. }
  122. else
  123. {
  124.     if($_SESSION['Login'] == "False")
  125.     {
  126.        ?>
  127. <form name="frmLogin" method="post" action="chklg.php">
  128.     <table>
  129.         <tr>
  130.             <td>
  131.                 Username
  132.             </td>
  133.             <td>
  134.                 <input type="text" name="txtUname" />
  135.             </td>
  136.         </tr>
  137.         <tr>
  138.             <td>
  139.                 Password
  140.             </td>
  141.             <td>
  142.                 <input type="password" name="txtPwrd" />
  143.             </td>
  144.         </tr>
  145.         <tr>
  146.             <td><input type="submit" name="btnInvio" /></td>
  147.         </tr>
  148.         <tr><td>Username o Password Errati</td></tr>
  149.     </table>
  150. </form>
  151. <?php
  152.     }
  153.     else
  154.     {
  155.         echo "Benvenuto, ".$_SESSION['UserLogin']."!";
  156.     }
  157. }
  158. ?>
Add Comment
Please, Sign In to add comment