Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assignment 4.html
- <!DOCTYPE html>
- <HTML>
- <HEAD>
- <TITLE>3η εργαστηριακή άσκηση</TITLE>
- <style>
- h1 {color: #0000ff;}
- </style>
- <script language="Javascript">
- var counter=0;
- function setCookie(name, value) {
- document.cookie= name + "=" + value;
- }
- function getCookie(name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++)
- {
- var c = ca[i];
- while (c.charAt(0)==' ')
- c = c.substring(1);
- if (c.indexOf(nameEQ) != -1)
- return c.substring(nameEQ.length);
- }
- return null;
- }
- function showCookies() {
- var name = getCookie("UsernameField");
- var prop = getCookie("PropertyField");
- var visits = getCookie("Visits");
- if (visits!=null) {
- visits=parseInt(visits)+1;
- alert ("Hello " + name +", you are a " +prop +" and this is your visit no. "+visits);
- setCookie("Visits", visits);
- }
- }
- function FormVal() {
- var usernameValue = document.Login.UsernameField.value;
- var passwordValue = document.Login.PasswordField.value;
- var propertyValue = document.Login.PropertyField.value;
- var visits= getCookie("Visits");
- //document.cookie= "Visits=" + counter;
- //document.cookie='Visits='+counter+'; expires=Fri, 3 Aug 2020 20:47:11 UTC';
- //counter++;
- if ( usernameValue == '' || passwordValue == '' ) {
- alert ("Error! No username or password provided");
- return(false);
- }
- else {
- setCookie('UsernameField', usernameValue);
- setCookie('PasswordField', passwordValue);
- setCookie('PropertyField', propertyValue);
- if (visits!=null) {
- visits=parseInt(visits)+1;
- setCookie("Visits", visits);
- }
- else {
- visits=1;
- }
- setCookie("Visits", visits);
- return(true);
- }
- }
- </script>
- </HEAD>
- <BODY>
- <h1>My first page
- </h1>
- <br /> <br />
- Homepage: <a href="http://www.cs.teikal.gr">http://www.cs.teikal.gr</a>
- <br />
- <br />
- My personal data: <br />
- <ul>
- <li><b>Dimitris Lilis Kokkoris</b></li>
- <li><i>AM: 2015072</i></li>
- <li><u>Tmima Mixanikwn Pliroforikis</u></li>
- </ul>
- <br /><br />
- <p> Please log in</p>
- <form name= "Login" method="post" action="http://localhost/readCookies.php" onsubmit="return FormVal()">
- <input type="text" name= "UsernameField" placeholder= "username">
- <input type="password" name= "PasswordField" placeholder= "password">
- <br />
- <input type="radio" name="PropertyField" value="Student" checked>Student
- <input type="radio" name="PropertyField" value="Professor">Professor <br />
- <input type="submit" value="Login"></input>
- </form>
- </BODY>
- </HTML>
- ----------------------------------------------------------------------------------------------------------------------------------
- showCookies.php
- <HTML>
- <BODY>
- <?php
- echo "Read input parameter Username: " . $_POST["UsernameField"];
- echo "<br>";
- echo "Read input parameter Password: " . $_POST["PasswordField"];
- echo "<br>";
- echo "Read input parameter Property: " . $_POST["PropertyField"];
- echo "<br>";
- print "<br>";
- print "<br>";
- print "Read cookies: <br>";
- foreach ($_COOKIE as $key=>$val)
- {
- print ($key . " => " . $val . "<br/>");
- }
- ?>
- </BODY>
- </HTML>
- ----------------------------------------------------------------------------------------------------------------------------------
- Assignment 5.html
- <!DOCTYPE html>
- <HTML>
- <HEAD>
- <TITLE>5η εργαστηριακή άσκηση</TITLE>
- <style>
- h1 {color: #0000ff;}
- </style>
- <script language="Javascript">
- var counter=0;
- function setCookie(name, value) {
- document.cookie= name + "=" + value;
- }
- function getCookie(name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++)
- {
- var c = ca[i];
- while (c.charAt(0)==' ')
- c = c.substring(1);
- if (c.indexOf(nameEQ) != -1)
- return c.substring(nameEQ.length);
- }
- return null;
- }
- function showCookies() {
- var name = getCookie("UsernameField");
- var prop = getCookie("PropertyField");
- var visits = getCookie("Visits");
- if (visits!=null) {
- visits=parseInt(visits)+1;
- alert ("Hello " + name +", you are a " +prop +" and this is your visit no. "+visits);
- setCookie("Visits", visits);
- }
- }
- function FormVal() {
- var usernameValue = document.Login.UsernameField.value;
- var passwordValue = document.Login.PasswordField.value;
- var propertyValue = document.Login.PropertyField.value;
- var visits = getCookie("Visits");
- //document.cookie= "Visits=" + counter;
- //document.cookie='Visits='+counter+'; expires=Fri, 3 Aug 2020 20:47:11 UTC';
- //counter++;
- if ( usernameValue == '' || passwordValue == '' ) {
- alert ("Error! No username or password provided");
- return(false);
- }
- else {
- setCookie('UsernameField', usernameValue);
- setCookie('PasswordField', passwordValue);
- setCookie('PropertyField', propertyValue);
- if (visits!=null) {
- visits=parseInt(visits)+1;
- setCookie("Visits", visits);
- }
- else {
- visits=1;
- }
- setCookie("Visits", visits);
- return(true);
- }
- }
- </script>
- </HEAD>
- <BODY>
- <h1>My first page
- </h1>
- <br /> <br />
- Homepage: <a href="http://www.cs.teikal.gr">http://www.cs.teikal.gr</a>
- <br />
- <br />
- My personal data: <br />
- <ul>
- <li><b>Dimitris Lilis Kokkoris</b></li>
- <li><i>AM: 2015072</i></li>
- <li><u>Tmima Mixanikwn Pliroforikis</u></li>
- </ul>
- <br /><br />
- <p> Please log in</p>
- <form name= "Login" method="post" action="http://localhost/login.php" onsubmit="return FormVal()">
- <input type="text" name= "UsernameField" placeholder= "username">
- <input type="password" name= "PasswordField" placeholder= "password">
- <br />
- <input type="radio" name="PropertyField" value="Student" checked>Student
- <input type="radio" name="PropertyField" value="Professor">Professor <br />
- <input type="submit" value="Login"></input>
- </form>
- </BODY>
- </HTML>
- ----------------------------------------------------------------------------------------------------------------------------------
- login.php
- <HTML>
- <BODY>
- <?php
- $username = $_POST["UsernameField"];
- $password = $_POST["PasswordField"];
- $database = "labusers";
- $DBusername = "root";
- $DBpassword = "";
- $conn = mysqli_connect("localhost", $DBusername, $DBpassword, $database);/* "root" , '' ,"labusers"); */
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $query = mysqli_query($conn, "SELECT * FROM users WHERE username='" . $username . "' AND password= '" . $password . "'" );
- $rows = mysqli_num_rows($query);
- if ($rows!=0) {
- print ("User: " . $username . " successfully logged in!");
- }
- else {
- print ("Wrong credentials, login failed!");
- }
- ?>
- </BODY>
- </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement