em89

ChangeProfile

Jul 14th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Change Profile</title>
  5.     <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7. </head>
  8. <body>
  9.     <div class="profileForm">
  10.        
  11.         <?php
  12.             if(file_exists('data.txt')){
  13.         $result=  file('data.txt');}
  14.         foreach ($result as $value) {
  15.             $columns=  explode('!', $value);
  16.         }
  17.         $upload = "upload/";
  18.         $upload = $upload . basename( $_FILES['uploaded']['name']) ;
  19.         $error = false;
  20.         if ($uploaded_size > 268435456) {
  21.             $error = true;
  22.         }
  23.         if ($error) {
  24.             echo "Your file is too big or invalid type.";
  25.         }
  26.         if (file_exists($target)) {
  27.             echo "The file $filename exists<br>";
  28.             $error = true;
  29.             exit;
  30.         }  
  31.  
  32.         else {
  33.             if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $upload)) {
  34.                 echo "The file ".basename( $_FILES['uploaded']['name']). " has been uploaded";
  35.             }
  36.             else {
  37.                 echo "Your file was not uploaded.";
  38.             }
  39.         }
  40.         $dir = "upload/";
  41.         chdir($dir);
  42.         array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files);
  43.         foreach($files as $filename) {
  44.             echo "<br>";
  45.             break;
  46.         }  
  47.         $images = $filename;
  48.         ?>
  49.         <form enctype="multipart/form-data" action="ChangeProfile.php" method="POST">
  50.             <span class="left">Profile picture:</span>
  51.             <img src="upload/<?php echo $images;?>" width="80px" height="80px">
  52.             <input type="file" name="uploaded" />
  53.             <input type="submit" value="submit" />
  54.         </form>
  55.         <form method="POST">
  56.             <br>
  57.             <label class="left" for="regName">User Name:</label>
  58.             <span><?php echo $columns[0]; ?></span>
  59.             <br>
  60.             <label class="left" for="passF">Password:</label>
  61.             <input type="password" name="regPass1" value="<?php echo $columns[1]; ?>" />
  62.             <br>
  63.             <label class="left" for="passF">Repeat Password:</label>
  64.             <input type="password" name="regPass2" value="" />
  65.             <br>
  66.             <label class="left" for="question">Secret Queston:</label>
  67.             <input type="text" name="question" value="<?php echo $columns[2]; ?>" />
  68.             <br>
  69.             <label class="left" for="answer">Secret Answer:</label>
  70.             <input type="text" name="answer" value="<?php echo $columns[3]; ?>" />
  71.             <br>
  72.             <label class="left" for="email">Email:</label>
  73.             <input type="text" name="email" value="<?php echo $columns[4]; ?>" />
  74.             <br>
  75.             <label class="left" for="fName">First Name:</label>
  76.             <input type="text" name="fName" value="<?php echo $columns[5]; ?>" />
  77.             <br>
  78.             <label class="left" for="lName">Last Name:</label>
  79.             <input type="text" name="lName" value="<?php echo $columns[6]; ?>" />
  80.             <br>
  81.             <label class="left">Sex:</label>
  82.             <input type="radio" name="sex" value="male" />male
  83.             <input type="radio" name="sex" value="male" />female
  84.             <br>
  85.             <label class="left" for="birth">Birthday:</label>
  86.             <input type="text" name="day" value="<?php echo $columns[8]; ?>" />
  87.             <input type="text" name="month" value="<?php echo $columns[9]; ?>" />
  88.             <input type="text" name="year" value="<?php echo $columns[10]; ?>" />
  89.             <hr>
  90.             <input type="submit" value="Change Profile" />
  91.         </form>
  92.     </div>
  93.     <?php
  94.         $userName = trim($_POST['regName']);
  95.         $userName = str_replace('!', '', $userName);
  96.         $userPass1 = trim($_POST['regPass1']);
  97.         $userPass1 = str_replace('!', '', $userPass1);
  98.         $userPass2 = trim($_POST['regPass2']);
  99.         $userPass2 = str_replace('!', '', $userPass2);
  100.         $userQuest = $_POST['question'];
  101.         $userAns = $_POST['answer'];
  102.         $userEmail = $_POST['email'];
  103.         $userFirst = $_POST['fName'];
  104.         $userLast = $_POST['lName'];
  105.         $sex = $_POST['sex'];
  106.         $birth = $_POST['day']."!".$_POST['month']."!".$_POST['year'];
  107.         $error = false;
  108.             if ($_POST) {
  109.                 if (empty($_POST['regPass1']) || empty($_POST['regPass2']) || empty($_POST['question']) || empty($_POST['answer']) || empty($_POST['email']) || empty($_POST['fName']) || empty($_POST['lName']) || empty($_POST['sex']) || empty($_POST['day']) || empty($_POST['month']) || empty($_POST['year'])) {
  110.                 echo "You have to fill all fields!";
  111.                 $error=true;
  112.                 }
  113.            
  114.                 if (!(preg_match('/^\w{6,}$/', $userPass1))) {
  115.                     echo '<p>Invalid Password!</p>';
  116.                     $error=true;
  117.                 }
  118.            
  119.                 if ($userPass1 != $userPass2) {
  120.                     echo "<p>Password doesn't match!</p>";
  121.                     $error=true;
  122.                 }
  123.            
  124.                 if (!(preg_match('/^\w{3,}$/', $userQuest))) {
  125.                     echo "<p>Use only letters and numbers!</p>";
  126.                     $error=true;
  127.                 }
  128.  
  129.                 if (!(preg_match('/^\w{3,}$/', $userAns))) {
  130.                     echo "<p>Use only letters and numbers!</p>";
  131.                     $error=true;
  132.                 }
  133.  
  134.                 $reg = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
  135.                 if (!(preg_match($reg, $userEmail))) {
  136.                     echo '<p>Invalid email!</p>';
  137.                     $error=true;
  138.                 }
  139.                 if (!(preg_match('/^\w{3,}$/', $userFirst))) {
  140.                     echo '<p>Invalid First Name!</p>';
  141.                     $error=true;
  142.                 }
  143.                
  144.                 if (!(preg_match('/^\w{3,}$/', $userLast))) {
  145.                     echo '<p>Invalid Last Name!</p>';
  146.                     $error=true;
  147.                 }
  148.                 if (!(preg_match('/[0-9]$/', $_POST['day']))) {
  149.                     echo '<p>Invalid date!</p>';
  150.                     $error=true;
  151.                 }
  152.                 if (!(preg_match('/[[a-zA-Z]$/', $_POST['month']))) {
  153.                     echo '<p>Invalid month!</p>';
  154.                     $error=true;
  155.                 }
  156.                 if (!(preg_match('/[0-9]{4}$/', $_POST['year']))) {
  157.                     echo '<p>Invalid year!</p>';
  158.                     $error=true;
  159.                 }
  160.    
  161.                 if (!$error) {
  162.                     $result = $userName."!".$userPass1."!".$userQuest."!".$userAns."!".$userEmail."!".$userFirst."!".$userLast."!".$sex."!"."!".$birth."\n";
  163.                     file_put_contents('data.txt', $result,FILE_APPEND);
  164.                 }
  165.                
  166.             }
  167.     ?>
  168. </body>
  169. </html>
Advertisement
Add Comment
Please, Sign In to add comment