Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryUllman committed Jul 10, 2017
1 parent 5ff4c82 commit 89954b2
Show file tree
Hide file tree
Showing 72 changed files with 528 additions and 831 deletions.
16 changes: 8 additions & 8 deletions ch02/multi.php
Expand Up @@ -9,35 +9,35 @@
<?php # Script 2.7 - multi.php

// Create one array:
$mexico = array(
$mexico = [
'YU' => 'Yucatan',
'BC' => 'Baja California',
'OA' => 'Oaxaca'
);
];

// Create another array:
$us = array(
$us = [
'MD' => 'Maryland',
'IL' => 'Illinois',
'PA' => 'Pennsylvania',
'IA' => 'Iowa'
);
];

// Create a third array:
$canada = array(
$canada = [
'QC' => 'Quebec',
'AB' => 'Alberta',
'NT' => 'Northwest Territories',
'YT' => 'Yukon',
'PE' => 'Prince Edward Island'
);
];

// Combine the arrays:
$n_america = array(
$n_america = [
'Mexico' => $mexico,
'United States' => $us,
'Canada' => $canada
);
];

// Loop through the countries:
foreach ($n_america as $country => $list) {
Expand Down
4 changes: 2 additions & 2 deletions ch08/handle_errors.php
Expand Up @@ -13,7 +13,7 @@
define('LIVE', FALSE);

// Create the error handler:
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) {

// Build the error message:
$message = "An error occurred in script '$e_file' on line $e_line: $e_message\n";
Expand All @@ -32,7 +32,7 @@ function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
} // End of my_error_handler() definition.

// Use my error handler:
set_error_handler ('my_error_handler');
set_error_handler('my_error_handler');

// Create errors:
foreach ($var as $v) {}
Expand Down
2 changes: 1 addition & 1 deletion ch08/report_errors.php
Expand Up @@ -12,7 +12,7 @@
ini_set('display_errors', 1);

// Adjust error reporting:
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);

// Create errors:
foreach ($var as $v) {}
Expand Down
9 changes: 5 additions & 4 deletions ch09/includes/footer.html
@@ -1,8 +1,9 @@
<!-- Script 3.3 - footer.html -->
<!-- End of the page-specific content. --></div>
<div id="footer">
<p>Copyright &copy; <a href="#">Plain and Simple</a> 2007 | Designed by <a href="http://www.edg3.co.uk/">edg3.co.uk</a> | Sponsored by <a href="http://www.opendesigns.org/">Open Designs</a> | Valid <a href="http://jigsaw.w3.org/css-validator/">CSS</a> &amp; <a href="http://validator.w3.org/">XHTML</a></p>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted"><p>Copyright &copy; 2017</p>
</div>
</footer>
</body>
</html>
35 changes: 19 additions & 16 deletions ch09/includes/header.html
@@ -1,23 +1,26 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="includes/style.css" type="text/css" media="screen">
<meta charset="utf-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="css/sticky-footer-navbar.css" rel="stylesheet">
</head>
<body>
<div id="header">
<h1>Your Website</h1>
<h2>catchy slogan...</h2>
</div>
<div id="navigation">
<ul>
<em><a href="index.php">Home Page</a></em>
<em><a href="register.php">Register</a></em>
<em><a href="view_users.php">View Users</a></em>
<em><a href="password.php">Change Password</a></em>
<em><a href="#">link five</a></em>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header"><a class="navbar-brand" href="#">Your Website</a></div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.php">Home</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="view_users.php">View Users</a></li>
<li><a href="password.php">Change Password</a></li>
</ul>
</div>
</div>
<div id="content"><!-- Start of the page-specific content. -->
</nav>
<div class="container">
<!-- Script 9.1 - header.html -->
121 changes: 0 additions & 121 deletions ch09/includes/style.css

This file was deleted.

35 changes: 22 additions & 13 deletions ch09/index.php 100644 → 100755
@@ -1,17 +1,26 @@
<?php # Script 3.4 - index.php
<?php # Script 3.7 - index.php #2

// This function outputs theoretical HTML
// for adding ads to a Web page.
function create_ad() {
echo '<div class="alert alert-info" role="alert"><p>This is an annoying ad! This is an annoying ad! This is an annoying ad! This is an annoying ad!</p></div>';
} // End of the function definition.

$page_title = 'Welcome to this Site!';
include ('./includes/header.html');
include('includes/header.html');

// Call the function:
create_ad();
?>
<h1 id="mainhead">Big Header</h1>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<h2>Subheader</h2>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>

<div class="page-header"><h1>Content Header</h1></div>
<p>This is where the page-specific content goes. This section, and the corresponding header, will change from one page to the next.</p>

<p>Volutpat at varius sed sollicitudin et, arcu. Vivamus viverra. Nullam turpis. Vestibulum sed etiam. Lorem ipsum sit amet dolore. Nulla facilisi. Sed tortor. Aenean felis. Quisque eros. Cras lobortis commodo metus. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit vitae, cursus sed, arcu lorem ipsum dolor sit amet.</p>

<?php
include ('./includes/footer.html');
// Call the function again:
create_ad();

include('includes/footer.html');
?>
14 changes: 7 additions & 7 deletions ch09/mysqli_connect.php
@@ -1,17 +1,17 @@
<?php # Script 9.2 - mysqli_connect.php

// This file contains the database access information.
// This file also establishes a connection to MySQL,
// This file contains the database access information.
// This file also establishes a connection to MySQL,
// selects the database, and sets the encoding.

// Set the database access information as constants:
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');
DEFINE('DB_USER', 'username');
DEFINE('DB_PASSWORD', 'password');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'sitename');

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error() );

// Set the encoding...
mysqli_set_charset($dbc, 'utf8');
16 changes: 8 additions & 8 deletions ch09/password.php
Expand Up @@ -2,14 +2,14 @@
// This page lets a user change their password.

$page_title = 'Change Your Password';
include ('includes/header.html');
include('includes/header.html');

// Check for form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

require ('../mysqli_connect.php'); // Connect to the db.
require('../mysqli_connect.php'); // Connect to the db.

$errors = array(); // Initialize an error array.
$errors = []; // Initialize an error array.

// Check for an email address:
if (empty($_POST['email'])) {
Expand Down Expand Up @@ -40,7 +40,7 @@
if (empty($errors)) { // If everything's OK.

// Check that they've entered the right email address/password combination:
$q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p') )";
$q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA2('$p', 512) )";
$r = @mysqli_query($dbc, $q);
$num = @mysqli_num_rows($r);
if ($num == 1) { // Match was made.
Expand All @@ -49,7 +49,7 @@
$row = mysqli_fetch_array($r, MYSQLI_NUM);

// Make the UPDATE query:
$q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]";
$q = "UPDATE users SET pass=SHA2('$np', 512) WHERE user_id=$row[0]";
$r = @mysqli_query($dbc, $q);

if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
Expand All @@ -72,7 +72,7 @@
mysqli_close($dbc); // Close the database connection.

// Include the footer and quit the script (to not show the form).
include ('includes/footer.html');
include('includes/footer.html');
exit();

} else { // Invalid email address/password combination.
Expand All @@ -97,10 +97,10 @@
?>
<h1>Change Your Password</h1>
<form action="password.php" method="post">
<p>Email Address: <input type="text" name="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" > </p>
<p>Email Address: <input type="email" name="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" > </p>
<p>Current Password: <input type="password" name="pass" size="10" maxlength="20" value="<?php if (isset($_POST['pass'])) echo $_POST['pass']; ?>" ></p>
<p>New Password: <input type="password" name="pass1" size="10" maxlength="20" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>" ></p>
<p>Confirm New Password: <input type="password" name="pass2" size="10" maxlength="20" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2']; ?>" ></p>
<p><input type="submit" name="submit" value="Change Password"></p>
</form>
<?php include ('includes/footer.html'); ?>
<?php include('includes/footer.html'); ?>

0 comments on commit 89954b2

Please sign in to comment.