home.php

1/1

lectures/5/src/login/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: .dtd"> 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42:


Home

Home

You are logged in!
log out You are not logged in!


Login Demos

include.php lectures/5/src/login/ 1:
// do some stuff

1/1

login5.php

1/2

lectures/5/src/login/ 1:
/** * login5.php * * A simple login module that checks a username and password * against a MySQL table with no encryption. * * David J. Malan * Computer Science E-75 * Harvard Extension School */ // enable sessions session_start(); // connect to database if (($connection = mysql_connect("", "", "")) === FALSE) die("Could not connect to database"); // select database if (mysql_select_db("", $connection) === FALSE) die("Could not select database"); // if username and password were submitted, check them if (isset($_POST["user"]) && isset($_POST["pass"])) { // prepare SQL $sql = sprintf("SELECT * FROM users WHERE user=’%s’", mysql_real_escape_string($_POST["user"])); // execute query $result = mysql_query($sql); if ($result === FALSE) die("Could not query database"); // check whether we found a row if (mysql_num_rows($result) == 1) { // fetch row $row = mysql_fetch_assoc($result); // check password if ($row["pass"] == $_POST["pass"]) { // remember that user’s logged in $_SESSION["authenticated"] = TRUE;

login5.php

2/2

lectures/5/src/login/ 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: .dtd"> 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84:

// redirect user to home page, using absolute path, per // http://us2.php.net/manual/en/function.header.php $host = $_SERVER["HTTP_HOST"]; $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\"); header("Location: http://$host$path/home.php"); exit; } } } ?>
Log In
" method="post">
Username:
Password:


login6.php

1/2

lectures/5/src/login/ 1:
/** * login6.php * * A simple login module that checks a username and password * against a MySQL table with no encryption by asking for a binary answer. * * David J. Malan * Computer Science E-75 * Harvard Extension School */ // enable sessions session_start(); // connect to database if (($connection = mysql_connect("", "", "")) === FALSE) die("Could not connect to database"); // select database if (mysql_select_db("", $connection) === FALSE) die("Could not select database"); // if username and password were submitted, check them if (isset($_POST["user"]) && isset($_POST["pass"])) { // prepare SQL $sql = sprintf("SELECT 1 FROM users WHERE user=’%s’ AND pass=’%s’", mysql_real_escape_string($_POST["user"]), mysql_real_escape_string($_POST["pass"])); // execute query $result = mysql_query($sql); if ($result === FALSE) die("Could not query database"); // check whether we found a row if (mysql_num_rows($result) == 1) { // remember that user’s logged in $_SESSION["authenticated"] = TRUE; // redirect user to home page, using absolute path, per // http://us2.php.net/manual/en/function.header.php $host = $_SERVER["HTTP_HOST"]; $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\"); header("Location: http://$host$path/home.php");

login6.php

2/2

lectures/5/src/login/ 48: 49: 50: 51: 52: 53: .dtd"> 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:

exit; } } ?>
Log In
" method="post">
Username:
Password:


login7.php

1/2

lectures/5/src/login/ 1:
/** * login7.php * * A simple login module that checks a username and password * against a MySQL table with weak encryption (well, a weak hash). * * David J. Malan * Computer Science E-75 * Harvard Extension School */ // enable sessions session_start(); // connect to database if (($connection = mysql_connect("", "", "")) === FALSE) die("Could not connect to database"); // select database if (mysql_select_db("", $connection) === FALSE) die("Could not select database"); // if username and password were submitted, check them if (isset($_POST["user"]) && isset($_POST["pass"])) { // prepare SQL $sql = sprintf("SELECT 1 FROM users WHERE user=’%s’ AND pass=PASSWORD(’%s’)", mysql_real_escape_string($_POST["user"]), mysql_real_escape_string($_POST["pass"])); // execute query $result = mysql_query($sql); if ($result === FALSE) die("Could not query database"); // check whether we found a row if (mysql_num_rows($result) == 1) { // remember that user’s logged in $_SESSION["authenticated"] = TRUE; // redirect user to home page, using absolute path, per // http://us2.php.net/manual/en/function.header.php $host = $_SERVER["HTTP_HOST"]; $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\"); header("Location: http://$host$path/home.php");

login7.php

2/2

lectures/5/src/login/ 48: 49: 50: 51: 52: 53: .dtd"> 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:

exit; } } ?>
Log In
" method="post">
Username:
Password:


login8.php

1/2

lectures/5/src/login/ 1:
/** * login8.php * * A simple login module that checks a username and password * against a MySQL table with strong encryption (but insecure secret). * * David J. Malan * Computer Science E-75 * Harvard Extension School */ // enable sessions session_start(); // connect to database if (($connection = mysql_connect("", "", "")) === FALSE) die("Could not connect to database"); // select database if (mysql_select_db("", $connection) === FALSE) die("Could not select database"); // if username and password were submitted, check them if (isset($_POST["user"]) && isset($_POST["pass"])) { // prepare SQL $sql = sprintf("SELECT 1 FROM users WHERE user=’%s’ AND pass=AES_ENCRYPT(’%s’, ’secret’)", mysql_real_escape_string($_POST["user"]), mysql_real_escape_string($_POST["pass"])); // execute query $result = mysql_query($sql); if ($result === FALSE) die("Could not query database"); // check whether we found a row if (mysql_num_rows($result) == 1) { // remember that user’s logged in $_SESSION["authenticated"] = TRUE; // redirect user to home page, using absolute path, per // http://us2.php.net/manual/en/function.header.php $host = $_SERVER["HTTP_HOST"]; $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\"); header("Location: http://$host$path/home.php");

login8.php

2/2

lectures/5/src/login/ 48: 49: 50: 51: 52: 53: .dtd"> 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:

exit; } } ?>
Log In
" method="post">
Username:
Password:


logout.php

1/1

lectures/5/src/login/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: .dtd"> 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:


Log Out

You are logged out!

home



lolcat.php

1/1

lectures/5/src/lolcat/ 1: 2: 5: 6: 7: 8: Lolcat of teh Day 9: 10: 11:
12:

Lolcat of teh Day

13: channel->item[0]; 17: preg_match("/^.* - (.*)description, $matches); 18: $alt = htmlspecialchars($matches[1], ENT_QUOTES); 19: $link = $item->link; 20: foreach ($item->children("http://search.yahoo.com/mrss/") as $content) 21: { 22: $attributes = $content->attributes(); 23: $src = $attributes["url"]; 24: } 25: print("’{$alt}’"); 26: 27: ?> 28:
29: 30: 31:

csv.php

1/1

lectures/5/src/lunch/development/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:

Lunch One for , coming right up!

lunch.php

1/1

lectures/5/src/lunch/development/ 1: 4: 5: 8: 9: 10: 11: Lunch 12: 13: 14:
15: Name: 16:

17: 18: xpath("/menu/category[@name=’Specialty Sandwiches’]/item") as $item): ?> 19: 20: 21: 28: 29: 30:
" name="item" type="radio" value="" /> 22: 27:
31:
32: 33:

sqlite.php

1/1

lectures/5/src/lunch/development/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // prepare fields $name = $dbh->quote($_POST["name"]); $item = $dbh->quote($_POST["item"]); // insert order $dbh->exec("INSERT INTO orders (name, item) VALUES($name, $item)"); } catch (PDOException $e) { die($e->getMessage()); } ?> Lunch One for , coming right up!

xml.php

1/1

lectures/5/src/lunch/development/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:

addChild("order"); $order->addChild("name", $_POST["name"]); $order->addChild("item", $_POST["item"]); // overwrite original XML file rewind($handle); fwrite($handle, $xml->asXML()); fclose($handle); ?> Lunch One for , coming right up!

home.php 1/1 include.php 1/1

remember that user's logged in. 46: $_SESSION["authenticated"] = TRUE;. 47: login5.php. 2/2 lectures/5/src/login/. 48: // redirect user to home page, using absolute path, per. 49: // http://us2.php.net/manual/en/function.header.php. 50: $host = $_SERVER["HTTP_HOST"];. 51: $path = rtrim(dirname($_SERVER["PHP_SELF"]), ...

28KB Sizes 0 Downloads 546 Views

Recommend Documents

No documents