Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. Assignment 4.html
  2.  
  3. <!DOCTYPE html>
  4. <HTML>
  5.  
  6. <HEAD>
  7.  
  8. <TITLE>3η εργαστηριακή άσκηση</TITLE>
  9. <style>
  10. h1 {color: #0000ff;}
  11. </style>
  12.  
  13. <script language="Javascript">
  14.  
  15. var counter=0;
  16.  
  17. function setCookie(name, value) {
  18. document.cookie= name + "=" + value;
  19. }
  20.  
  21. function getCookie(name) {
  22. var nameEQ = name + "=";
  23. var ca = document.cookie.split(';');
  24.  
  25. for(var i=0;i < ca.length;i++)
  26. {
  27. var c = ca[i];
  28. while (c.charAt(0)==' ')
  29. c = c.substring(1);
  30.  
  31. if (c.indexOf(nameEQ) != -1)
  32. return c.substring(nameEQ.length);
  33. }
  34.  
  35. return null;
  36. }
  37.  
  38. function showCookies() {
  39. var name = getCookie("UsernameField");
  40. var prop = getCookie("PropertyField");
  41. var visits = getCookie("Visits");
  42. if (visits!=null) {
  43. visits=parseInt(visits)+1;
  44. alert ("Hello " + name +", you are a " +prop +" and this is your visit no. "+visits);
  45. setCookie("Visits", visits);
  46. }
  47. }
  48.  
  49. function FormVal() {
  50.  
  51. var usernameValue = document.Login.UsernameField.value;
  52. var passwordValue = document.Login.PasswordField.value;
  53. var propertyValue = document.Login.PropertyField.value;
  54. var visits= getCookie("Visits");
  55.  
  56. //document.cookie= "Visits=" + counter;
  57. //document.cookie='Visits='+counter+'; expires=Fri, 3 Aug 2020 20:47:11 UTC';
  58. //counter++;
  59.  
  60. if ( usernameValue == '' || passwordValue == '' ) {
  61. alert ("Error! No username or password provided");
  62. return(false);
  63. }
  64. else {
  65. setCookie('UsernameField', usernameValue);
  66. setCookie('PasswordField', passwordValue);
  67. setCookie('PropertyField', propertyValue);
  68. if (visits!=null) {
  69. visits=parseInt(visits)+1;
  70. setCookie("Visits", visits);
  71. }
  72. else {
  73. visits=1;
  74. }
  75. setCookie("Visits", visits);
  76.  
  77.  
  78. return(true);
  79. }
  80. }
  81.  
  82. </script>
  83. </HEAD>
  84.  
  85. <BODY>
  86.  
  87. <h1>My first page
  88. </h1>
  89.  
  90. <br /> <br />
  91. Homepage: <a href="http://www.cs.teikal.gr">http://www.cs.teikal.gr</a>
  92. <br />
  93. <br />
  94.  
  95. My personal data: <br />
  96.  
  97. <ul>
  98. <li><b>Dimitris Lilis Kokkoris</b></li>
  99. <li><i>AM: 2015072</i></li>
  100. <li><u>Tmima Mixanikwn Pliroforikis</u></li>
  101. </ul>
  102.  
  103. <br /><br />
  104. <p> Please log in</p>
  105. <form name= "Login" method="post" action="http://localhost/readCookies.php" onsubmit="return FormVal()">
  106.  
  107. <input type="text" name= "UsernameField" placeholder= "username">
  108. <input type="password" name= "PasswordField" placeholder= "password">
  109. <br />
  110.  
  111. <input type="radio" name="PropertyField" value="Student" checked>Student
  112. <input type="radio" name="PropertyField" value="Professor">Professor <br />
  113.  
  114. <input type="submit" value="Login"></input>
  115. </form>
  116.  
  117.  
  118. </BODY>
  119.  
  120.  
  121.  
  122.  
  123. </HTML>
  124. ----------------------------------------------------------------------------------------------------------------------------------
  125. showCookies.php
  126.  
  127. <HTML>
  128.  
  129. <BODY>
  130. <?php
  131.  
  132. echo "Read input parameter Username: " . $_POST["UsernameField"];
  133. echo "<br>";
  134. echo "Read input parameter Password: " . $_POST["PasswordField"];
  135. echo "<br>";
  136. echo "Read input parameter Property: " . $_POST["PropertyField"];
  137. echo "<br>";
  138.  
  139. print "<br>";
  140. print "<br>";
  141.  
  142. print "Read cookies: <br>";
  143. foreach ($_COOKIE as $key=>$val)
  144. {
  145. print ($key . " => " . $val . "<br/>");
  146. }
  147. ?>
  148.  
  149. </BODY>
  150.  
  151. </HTML>
  152.  
  153. ----------------------------------------------------------------------------------------------------------------------------------
  154. Assignment 5.html
  155.  
  156. <!DOCTYPE html>
  157. <HTML>
  158.  
  159. <HEAD>
  160.  
  161. <TITLE>5η εργαστηριακή άσκηση</TITLE>
  162. <style>
  163. h1 {color: #0000ff;}
  164. </style>
  165.  
  166. <script language="Javascript">
  167.  
  168. var counter=0;
  169.  
  170. function setCookie(name, value) {
  171. document.cookie= name + "=" + value;
  172. }
  173.  
  174. function getCookie(name) {
  175. var nameEQ = name + "=";
  176. var ca = document.cookie.split(';');
  177.  
  178. for(var i=0;i < ca.length;i++)
  179. {
  180. var c = ca[i];
  181. while (c.charAt(0)==' ')
  182. c = c.substring(1);
  183.  
  184. if (c.indexOf(nameEQ) != -1)
  185. return c.substring(nameEQ.length);
  186. }
  187.  
  188. return null;
  189. }
  190.  
  191. function showCookies() {
  192. var name = getCookie("UsernameField");
  193. var prop = getCookie("PropertyField");
  194. var visits = getCookie("Visits");
  195. if (visits!=null) {
  196. visits=parseInt(visits)+1;
  197. alert ("Hello " + name +", you are a " +prop +" and this is your visit no. "+visits);
  198. setCookie("Visits", visits);
  199. }
  200. }
  201.  
  202. function FormVal() {
  203.  
  204. var usernameValue = document.Login.UsernameField.value;
  205. var passwordValue = document.Login.PasswordField.value;
  206. var propertyValue = document.Login.PropertyField.value;
  207. var visits = getCookie("Visits");
  208.  
  209. //document.cookie= "Visits=" + counter;
  210. //document.cookie='Visits='+counter+'; expires=Fri, 3 Aug 2020 20:47:11 UTC';
  211. //counter++;
  212.  
  213. if ( usernameValue == '' || passwordValue == '' ) {
  214. alert ("Error! No username or password provided");
  215. return(false);
  216. }
  217. else {
  218. setCookie('UsernameField', usernameValue);
  219. setCookie('PasswordField', passwordValue);
  220. setCookie('PropertyField', propertyValue);
  221. if (visits!=null) {
  222. visits=parseInt(visits)+1;
  223. setCookie("Visits", visits);
  224. }
  225. else {
  226. visits=1;
  227. }
  228. setCookie("Visits", visits);
  229.  
  230. return(true);
  231. }
  232. }
  233.  
  234. </script>
  235. </HEAD>
  236.  
  237. <BODY>
  238.  
  239. <h1>My first page
  240. </h1>
  241.  
  242. <br /> <br />
  243. Homepage: <a href="http://www.cs.teikal.gr">http://www.cs.teikal.gr</a>
  244. <br />
  245. <br />
  246.  
  247. My personal data: <br />
  248.  
  249. <ul>
  250. <li><b>Dimitris Lilis Kokkoris</b></li>
  251. <li><i>AM: 2015072</i></li>
  252. <li><u>Tmima Mixanikwn Pliroforikis</u></li>
  253. </ul>
  254.  
  255. <br /><br />
  256. <p> Please log in</p>
  257. <form name= "Login" method="post" action="http://localhost/login.php" onsubmit="return FormVal()">
  258.  
  259. <input type="text" name= "UsernameField" placeholder= "username">
  260. <input type="password" name= "PasswordField" placeholder= "password">
  261. <br />
  262.  
  263. <input type="radio" name="PropertyField" value="Student" checked>Student
  264. <input type="radio" name="PropertyField" value="Professor">Professor <br />
  265.  
  266. <input type="submit" value="Login"></input>
  267. </form>
  268.  
  269.  
  270. </BODY>
  271.  
  272.  
  273.  
  274.  
  275. </HTML>
  276.  
  277. ----------------------------------------------------------------------------------------------------------------------------------
  278. login.php
  279.  
  280. <HTML>
  281.  
  282. <BODY>
  283.  
  284. <?php
  285.  
  286. $username = $_POST["UsernameField"];
  287. $password = $_POST["PasswordField"];
  288. $database = "labusers";
  289. $DBusername = "root";
  290. $DBpassword = "";
  291.  
  292. $conn = mysqli_connect("localhost", $DBusername, $DBpassword, $database);/* "root" , '' ,"labusers"); */
  293. if (!$conn) {
  294. die("Connection failed: " . mysqli_connect_error());
  295. }
  296.  
  297. $query = mysqli_query($conn, "SELECT * FROM users WHERE username='" . $username . "' AND password= '" . $password . "'" );
  298. $rows = mysqli_num_rows($query);
  299. if ($rows!=0) {
  300. print ("User: " . $username . " successfully logged in!");
  301. }
  302. else {
  303. print ("Wrong credentials, login failed!");
  304. }
  305.  
  306.  
  307. ?>
  308.  
  309. </BODY>
  310.  
  311. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement