Guest User

Untitled

a guest
May 3rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <style>
  5. .error {
  6. color:red;
  7. }
  8.  
  9. .button {
  10. background-color: #4CAF50;
  11. border: none;
  12. color: white;
  13. padding: 10px 25px;
  14. text-align: center;
  15. text-decoration: none;
  16. display: inline-block;
  17. font-size: 16px;
  18. margin: 4px 2px;
  19. cursor: pointer;
  20. }
  21. .div1 {
  22. background-color: #f2f2f2;
  23. margin-top: -19px;
  24. margin-bottom: -25px;
  25. margin-left: -19px;
  26. }
  27.  
  28. .copy {
  29. border-radius: 4px;
  30. padding: 6px 20px;
  31. border-style: ridge;
  32. }
  33.  
  34. .copy1{
  35. border-radius: 4px;
  36. padding: 6px 28px;
  37. border-style: ridge;
  38. }
  39.  
  40. .copy2 {
  41. border-radius: 4px;
  42. padding: 4px 2px;
  43.  
  44. }
  45. </style>
  46. </head>
  47. <body>
  48.  
  49. <?php
  50. // define variables and set to empty values
  51. include_once 'connect.php';
  52. $nameErr = $emailErr = $usernameErr = $passwordErr = $DateOfBirthErr =
  53. $departmentErr = $ageErr = "";
  54. $name = $email = $username = $password = $DateOfBirth = $department =
  55. $age = "";
  56.  
  57. if (isset($_POST['submit'])) {
  58. if (empty($_POST["name"])) {
  59. $nameErr = "Name is required";
  60. } else {
  61. $name = test_input($_POST["name"]);
  62. // check if name only contains letters and whitespace
  63. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  64. $nameErr = "Only letters and white space allowed";
  65. }
  66. }
  67.  
  68. if (empty($_POST["email"])) {
  69. $emailErr = "Email is required";
  70. } else {
  71. $email = test_input($_POST["email"]);
  72. // check if e-mail address is well-formed
  73. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  74. $emailErr = "Invalid email format";
  75. }
  76. }
  77.  
  78. if (empty($_POST["username"])) {
  79. $usernameErr = "Username is required";
  80. } else {
  81. $username = test_input($_POST["username"]);
  82. // check if name only contains letters and whitespace
  83. if (!preg_match("/^[a-zA-Z ]*$/",$username)) {
  84. $usernameErr = "Only letters and white space allowed";
  85. }
  86. }
  87.  
  88. if (empty($_POST["password"])) {
  89. $passwordErr = "Password is required";
  90. } else {
  91. $password = test_input($_POST["password"]);
  92. $hashed_password = password_hash($password, PASSWORD_DEFAULT);
  93. // check weather password is alphanumeric
  94. if(!preg_match('/^(?=.*d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{6,}$/',
  95. $password))
  96. {
  97. $passwordErr = "Password must be alphanumeric and atleast 6 characters
  98. long!";
  99. }
  100. }
  101.  
  102. if (empty($_POST["Date_of_birth"])) {
  103. $DateOfBirthErr = "Date Of Birth is required";
  104. } else {
  105. $DateOfBirth = test_input($_POST["Date_of_birth"]);
  106. }
  107.  
  108. if (empty($_POST["department"])) {
  109. $departmentErr = "Department is required";
  110. } else {
  111. $department = test_input($_POST["department"]);
  112. }
  113.  
  114. if (empty($_POST["age"])) {
  115. $ageErr = "Age is required";
  116. } else {
  117. $age = test_input($_POST["age"]);
  118. }
  119.  
  120. if($nameErr == "" && $emailErr == "" && $usernameErr == "" &&
  121. $passwordErr ==
  122. "")
  123. {
  124. $check="SELECT * FROM users WHERE username = '$_POST[username]'";
  125. $rs = mysqli_query($mysqli,$check);
  126. $da = mysqli_fetch_array($rs, MYSQLI_NUM);
  127. if($da[0] > 0) {
  128. echo "Username Already in Exists<br/>";
  129. }
  130.  
  131. else
  132. {
  133. $sql = "INSERT INTO users(`id`,`username`, `password`, `email` , `name` ,
  134. `Date_of_birth` , `department` ,`age`)
  135. VALUES ('','".$username."', '".$hashed_password."', '".$email."' ,
  136. '".$name."' , '".$DateOfBirth."' , '".$department."' , '".$age."')";
  137.  
  138. if (mysqli_query($mysqli, $sql)) {
  139. echo "Registered successfully";
  140. } else {
  141. echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
  142. }
  143. mysqli_close($mysqli);
  144. }
  145. }
  146.  
  147. }
  148.  
  149. function test_input($data) {
  150. $data = trim($data);
  151. $data = stripslashes($data);
  152. $data = htmlspecialchars($data);
  153. return $data;
  154. }
  155. ?>
  156.  
  157.  
  158. <div style="padding-left: 250px" class="div1">
  159. <h2 style="color:#009999">Registration Form :</h2>
  160. <p><span class="error">All fields are required </span></p>
  161. <form method="post" action="">
  162. <span style="color:#0099ff">Name: </span>
  163. <input type="text" name="name" class= "copy" style="margin-left: 52px"
  164. value ="<?php
  165. if (isset($name))
  166. echo $name;
  167. ?>">
  168. <span class="error"> <?php echo $nameErr;?></span>
  169. <br><br>
  170. <span style="color:#0099ff"> E-mail: </span>
  171. <input type="text" name="email" class= "copy" style="margin-left:
  172. 48px" value
  173. ="<?php
  174. if (isset($email))
  175. echo $email;
  176. ?>">
  177. <span class="error"><?php echo $emailErr;?></span>
  178. <br><br>
  179. <span style="color:#0099ff"> Username: </span>
  180. <input type="text" name="username" class= "copy" style="margin-
  181. left:26px"
  182. value ="<?php
  183. if (isset($username))
  184. echo $username;
  185. ?>">
  186. <span class="error"> <?php echo $usernameErr;?></span>
  187. <br><br>
  188. <span style="color:#0099ff"> Password: </span>
  189. <input type="password" name="password" class= "copy" style="margin-
  190. left:30px">
  191. <span class="error"> <?php echo $passwordErr;?></span>
  192. <br><br>
  193. <span style="color:#0099ff"> Date Of Birth : </span>
  194. <input type="date" class= "copy1" name="Date_of_birth" value ="<?php
  195. if (isset($DateOfBirth))
  196. echo $DateOfBirth;
  197. ?>">
  198. <span class="error"> <?php echo $DateOfBirthErr;?></span>
  199. <br><br>
  200. <span style="color:#0099ff"> Age : </span>
  201. <input type="number" name="age" class= "copy" style="margin-left:62px"
  202. value
  203. ="<?php
  204. if (isset($age))
  205. echo $age;
  206. ?>">
  207. <span class="error"> <?php echo $ageErr;?></span>
  208. <br><br>
  209. <span style="color:#0099ff"> Department : </span>
  210. <select name="department" class= "copy2" style="margin-left:14px" value
  211. ="<?
  212. php
  213. if (isset($department))
  214. echo $department;
  215. ?>">
  216. <option value="EE">Electrical & Electronics</option>
  217. <option value="EC">Electronics & Communication</option>
  218. <option value="ME">Mechanical</option>
  219. <option value="CS">Computer Science</option>
  220. <option value="CV">Civil</option>
  221. <option value="IS">Information Science</option>
  222. </select>
  223. <span class="error"> <?php echo $departmentErr;?></span>
  224. <br><br>
  225. <input type="submit" class="button" name="submit" value="Register">
  226. <p style="color:black">Already Registered? <a
  227. href="login.php">Login</a>.
  228. </p>
  229. </form>
  230. </div>
  231. </body>
  232. </html>
  233.  
  234. <?php
  235.  
  236. $error="";
  237. include_once 'connect.php';
  238. if(isset($_SESSION['login_user']))
  239. {
  240. header('location:welcome.php');
  241. }
  242. session_start();
  243.  
  244. if($_SERVER["REQUEST_METHOD"] == "POST") {
  245. // username and password sent from form
  246.  
  247. $myusername = mysqli_real_escape_string($mysqli,$_POST['username']);
  248. $mypassword = mysqli_real_escape_string($mysqli,$_POST['password']);
  249.  
  250. $sql = "SELECT * FROM users WHERE username = '$myusername' ";
  251. $result = mysqli_query($mysqli,$sql);
  252. $row = mysqli_fetch_array($result);
  253. $hashed_password=$row['password'];
  254. if(password_verify($mypassword, $hashed_password)) {
  255.  
  256. $_SESSION['login_user'] = $myusername;
  257.  
  258. header("location: welcome.php");
  259. exit();
  260. }
  261. else
  262. {
  263. $error = " Invalid Username or Password ";
  264. }
  265. }
  266.  
  267.  
  268. ?>
  269. <html>
  270.  
  271. <head>
  272. <title>Login Page</title>
  273.  
  274. <style type = "text/css">
  275. body {
  276. font-family:Arial, Helvetica, sans-serif;
  277. font-size:14px;
  278. }
  279. label {
  280. font-weight:bold;
  281. width:100px;
  282. font-size:14px;
  283. }
  284. .box {
  285. border:#666666 solid 1px;
  286. }
  287.  
  288. .button {
  289. background-color: #4CAF50;
  290. border: none;
  291. color: white;
  292. padding: 10px 20px;
  293. text-align: center;
  294. text-decoration: none;
  295. display: inline-block;
  296. font-size: 12px;
  297. margin: 4px 2px;
  298. cursor: pointer;
  299. }
  300. </style>
  301.  
  302. </head>
  303.  
  304. <body bgcolor = "#FFFFFF">
  305.  
  306. <div align = "center">
  307.  
  308. <div style = "margin:30px">
  309.  
  310. <form action = "" method = "post">
  311. <label>Username : </label><input type = "text" name =
  312. "username" class = "box"/><br /><br />
  313. <label>Password : </label><input type = "password" name =
  314. "password" class = "box" /><br/><br />
  315. <input class="button" type = "submit" value = " login "/><br
  316. />
  317. </form>
  318.  
  319. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?
  320. php echo $error; ?></div>
  321.  
  322. </div>
  323.  
  324. </div>
  325.  
  326. </body>
  327. </html>
  328.  
  329. <?php
  330.  
  331. include('session.php');
  332. if(!isset($_SESSION['login_user'])){
  333. header('location:login.php');
  334. }
  335.  
  336. ?>
  337.  
  338.  
  339. <html>
  340.  
  341. <head>
  342. <title>Welcome </title>
  343. </head>
  344.  
  345. <body>
  346. <h1>Welcome <?php echo $login_session; ?></h1>
  347. <h2><a href = "logout.php">logOut</a></h2>
  348.  
  349. </body>
  350.  
  351. </html>
  352.  
  353. <?php
  354. include_once 'connect.php';
  355. session_start();
  356.  
  357. $user_check = $_SESSION['login_user'];
  358.  
  359. $ses_sql = mysqli_query($mysqli,"select username from users where username
  360. =
  361. '$user_check' ");
  362.  
  363. $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
  364.  
  365. $login_session = $row['username'];
  366.  
  367. if(!isset($_SESSION['login_user'])){
  368. header("location:login.php");
  369. }
  370.  
  371.  
  372. ?>
  373.  
  374. <?php
  375. session_start();
  376.  
  377. if(session_destroy()) {
  378. header("Location: login.php");
  379. }
  380. ?>
  381.  
  382. <?php
  383.  
  384.  
  385. $databaseHost = 'localhost';
  386. $databaseName = 'amith';
  387. $databaseUsername = 'root';
  388. $databasePassword = '';
  389.  
  390. $mysqli = mysqli_connect($databaseHost, $databaseUsername,
  391. $databasePassword, $databaseName);
  392.  
  393.  
  394.  
  395. ?>
Add Comment
Please, Sign In to add comment