[ create a new paste ] login | about

Link: http://codepad.org/v6njjgfU    [ raw code | output | fork ]

sebastian111 - PHP, pasted on Mar 4:
                   <form action="testinl2.php" method="POST">
                       
                       <p>Username <input type="text" name="username" id="namn" /></p>
                       <p>Password<input type="text" name="password" id="namn" /></p>
                       <input type="submit" name="Logg" id="Namn" value="Login"/> <!--Button-->
                       <input type="submit" name="register" id="Namn" value="Register"/> <!--Button-->
    
 /*
      * i know its not recommended to store username and pass 
       in a txt file but its for learning purposes!!!!  
      */
          
<?php 
 //session_start(); // session
      
       
   if(isset($_POST['register'])) //  
{
    $user  = $_POST['username'];
    $password=$_POST['password'].PHP_EOL;
    $fh = fopen("file.txt","a+");
    fwrite($fh,$user." ".$password); //write to txtfile
     
     fclose($fh);
}


if(isset($_POST['Logg']))
{
//$_SESSION['username']=$user; 
//$_SESSION['password']=$password;

 $file = file_get_contents("file.txt"); // Returns a string

    $result = explode("\n",$file);  // explode /n
    foreach($result as $one)
     {
    $results = explode(" ",$one);  // explode through space
    print_r($results); // print results for testing
     }
 


for($i=0; $i< count($results); $i++){

    if($results[$i] === $user && $results[$i+1] === $password)
    {

        echo 'Correct'; // Test if it works
   }
}
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
                   <form action="testinl2.php" method="POST">
                       
                       <p>Username <input type="text" name="username" id="namn" /></p>
                       <p>Password<input type="text" name="password" id="namn" /></p>
                       <input type="submit" name="Logg" id="Namn" value="Login"/> <!--Button-->
                       <input type="submit" name="register" id="Namn" value="Register"/> <!--Button-->
    
 /*
      * i know its not recommended to store username and pass 
       in a txt file but its for learning purposes!!!!  
      */
          


Create a new paste based on this one


Comments: