Lengstorf / Blom Hansen | PHP for Absolute Beginners | E-Book | sack.de
E-Book

E-Book, Englisch, 236 Seiten, eBook

Lengstorf / Blom Hansen PHP for Absolute Beginners


2. Auflage 2014
ISBN: 978-1-4302-6814-7
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 236 Seiten, eBook

ISBN: 978-1-4302-6814-7
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark



PHP is a server-side scripting language that enables you to develop dynamic sites that engage users in ways that are simply not possible using only HTML and CSS. PHP for Absolute Beginners takes a practical approach to teaching you how to build dynamic content for your website using PHP. You’ll quickly get started with practical PHP projects, learning how to build a dynamic image gallery. By the end of the book you’ll will have developed a personal blog complete with a password protected admin module. PHP for Absolute Beginners won't swamp you with every detail of the full PHP language up front – instead, you’ll be introduced to a small, versatile subset of PHP and learn to use it creatively to develop dynamic web sites. In the process you will learn to use variables, control structures, functions, and objects to your advantage. You will learn how to plan and create databases and how to organize your PHP scripts beautifully. At the end of the book, you will be a confident PHP user, ready to take the next steps in creating great websites.
Lengstorf / Blom Hansen PHP for Absolute Beginners jetzt bestellen!

Zielgruppe


Popular/general

Weitere Infos & Material


1;Contents at a Glance;3
2;Contents;225
3;About the Authors;234
4;About the Technical Reviewer;235
5;Acknowledgments;236
6;Introduction;4
7;Part I: PHP/MySQL Basics;5
7.1;Chapter 1: Setting Up a PHP Development Environment;6
7.1.1;Why You Need Apache, MySQL, and PHP;6
7.1.1.1;How PHP Works;7
7.1.1.2;Apache and What It Does;7
7.1.1.3;Storing Info with MySQL;7
7.1.2;Installing PHP, Apache, and MySQL;8
7.1.2.1;Installing XAMPP;8
7.1.2.1.1;Step 1: Download XAMPP;8
7.1.2.1.2;Step 2: Open the Installer and Follow the Instructions;8
7.1.2.1.3;Step 3: Test XAMPP to Ensure Proper Installation;13
7.1.2.2;Open the XAMPP Control Panel;13
7.1.2.3;What If Apache Isn’t Running?;14
7.1.2.4;Verify That Apache and PHP Are Running;15
7.1.3;Choosing a PHP Editor;15
7.1.4;Creating Your First PHP File;16
7.1.5;Running Your First PHP Script;17
7.1.6;Summary;18
7.2;Chapter 2: Understanding PHP: Language Basics;19
7.2.1;Embedding PHP Scripts;20
7.2.1.1;Using echo;21
7.2.1.2;What Is a Variable?;21
7.2.1.2.1;Storing Values in a Variable;21
7.2.1.2.2;A Variable Is a Placeholder;21
7.2.1.2.3;Valid PHP Variable Names;22
7.2.1.3;Displaying PHP Errors;22
7.2.2;Creating an HTML5 Page with PHP;23
7.2.2.1;Including a Simple Page Template;24
7.2.2.2;Returning Values;24
7.2.2.3;Including the Template;24
7.2.2.4;Commenting Your Code;25
7.2.2.4.1;Block and Single-Line Comments;25
7.2.2.5;Avoiding Naming Conflicts;25
7.2.2.5.1;The Object Operator;26
7.2.2.5.2;Using a StdClass Object for Page Data;26
7.2.2.5.3;Object Properties Are Like Variables;27
7.2.3;Page Views;27
7.2.3.1;Making a Dynamic Site Navigation;27
7.2.3.2;Passing Information with PHP;28
7.2.3.3;Accessing URL Variables;29
7.2.3.4;Using isset(?) to Test If a Variable Is Set;29
7.2.3.5;$_GET, a Superglobal Array;29
7.2.3.6;Including Page Views Dynamically;30
7.2.3.7;Concatenation;31
7.2.3.8;Strict Naming Convention;31
7.2.3.9;Displaying a Default Page;31
7.2.4;Validating Your HTML;32
7.2.5;Styling the Site with CSS;32
7.2.6;Declaring a Page_Data Class;33
7.2.6.1;Classes Make Objects;34
7.2.6.2;Highlighting Current Navigation Item with a Dynamic Style Rule;34
7.2.6.2.1;Taking a Closer Look at the Dynamic CSS;36
7.2.7;Summary;36
7.3;Chapter 3: Form Management;37
7.3.1;What Are Forms?;37
7.3.2;Setting Up a New PHP Project;38
7.3.2.1;Seeing for Yourself;40
7.3.2.2;Creating a Dynamic Navigation;40
7.3.2.3;Creating Page Views for the Form;41
7.3.2.3.1;Displaying Page Views on index.php;41
7.3.2.4;Spending Your Time Wisely: Conventions and Reuse;42
7.3.3;A Super-Simple Search Form;42
7.3.3.1;Trying Your Search Form;42
7.3.3.2;Forms Encode URL Variables;43
7.3.3.2.1;A Name Attribute Declares the Name of a URL Variable;43
7.3.3.2.2;The Element and Some Common Types;44
7.3.3.2.3;Understanding the Method Attribute;44
7.3.4;Named PHP Functions;44
7.3.4.1;The Basic Syntax for Functions;44
7.3.4.2;Using Function Arguments for Increased Flexibility;46
7.3.5;Creating a Form for the Quiz;46
7.3.5.1;Showing the Quiz Form;46
7.3.5.1.1;Using and ;47
7.3.5.1.2;The POST Method;47
7.3.5.1.3;Using the $_POST Superglobal;47
7.3.5.1.4;$_POST Is an Array;48
7.3.5.1.5;If and Else Explained;50
7.3.5.2;Evaluating the Quiz Response;50
7.3.5.2.1;The Identical Comparison Operator;50
7.3.6;Curly’s Law: Do One Thing;51
7.3.6.1;Meaningful Names;51
7.3.6.1.1;Code Is Poetry;52
7.3.7;Styling Forms;52
7.3.8;Exercises;53
7.3.9;Summary;53
7.4;Chapter 4: Building a Dynamic Image Gallery with Image Upload;54
7.4.1;Setting Up a Dynamic Site;54
7.4.1.1;Prerequisites: A Folder with Some Images;54
7.4.1.2;Creating a Navigation;55
7.4.1.3;Creating Two Dummy Page View Files;55
7.4.1.4;Creating the Index File;55
7.4.1.5;Time to Test;56
7.4.2;Adding Two Style Sheets to One Page;56
7.4.2.1;Staying DRY;56
7.4.2.2;Improving the Page_Data Class with a Method;57
7.4.2.3;Is It a Function or a Method?;57
7.4.2.4;What Is $this?;57
7.4.2.5;Using the New Method;58
7.4.2.6;You Can Only Use Methods That Are Declared;58
7.4.3;Preparing a Function for Displaying Images;58
7.4.3.1;Iteration;59
7.4.3.2;Using a DirectoryIterator to Find Files in a Folder;59
7.4.3.3;Showing All Images;60
7.4.4;Creating a Form View;61
7.4.4.1;Showing a Form for Uploading Images;62
7.4.4.2;$_FILES;62
7.4.4.2.1;tmp_name;63
7.4.4.2.2;error;63
7.4.5;Uploading Files with PHP;63
7.4.5.1;Planning an Uploader Class;64
7.4.5.1.1;UML;64
7.4.5.1.2;Uploader Class Requirements;64
7.4.5.1.3;The Magic Method __ construct();65
7.4.5.1.4;Saving the Uploaded File;66
7.4.5.2;Using the Uploader Class;67
7.4.5.2.1;What Could Go Wrong?;67
7.4.5.3;The Single Responsibility Principle;67
7.4.6;Summary;68
7.5;Chapter 5: Spicing Up Your Image Gallery with JavaScript and CSS;69
7.5.1;Client-Side vs. Server-Side Programming;69
7.5.2;Coding a Lightbox Gallery;70
7.5.2.1;Embedding an External JavaScript File;70
7.5.2.2;Preparing the Page_Data Class for JavaScript Files;70
7.5.2.3;Preparing the Page Template for JavaScript Files;71
7.5.2.4;Writing and Running an External JavaScript File;72
7.5.2.5;Using window.console.log();72
7.5.2.6;JavaScript Arrays;73
7.5.2.6.1;Using var to Declare a Variable;73
7.5.2.6.2;Looping Through Array Items;73
7.5.2.7;Simple Progressive Enhancement;74
7.5.2.7.1;Using Event Listeners;74
7.5.2.7.1.1;The Event;75
7.5.2.7.1.2;The Event Handler;75
7.5.2.7.1.3;The Optional useCapture;75
7.5.2.8;Creating Markup for the Overlay and Big Image;75
7.5.2.8.1;document.querySelector(?);76
7.5.2.9;Showing the Overlay;76
7.5.2.10;Hiding the Overlay and Resize Thumbnails;76
7.5.2.10.1;Only Showing Thumbnails to Capable Browsers;78
7.5.2.10.2;Getting an Array of HTML Elements with querySelectorAll(?);78
7.5.2.11;Showing a Big Image;78
7.5.2.11.1;Using the MouseEvent Object;79
7.5.2.11.2;Toggling;80
7.5.2.11.3;Manipulating Attributes;80
7.5.2.12;Hiding the Big Image;81
7.5.2.13;Using a CSS Animation;81
7.5.2.14;Coding Challenge;82
7.5.3;Summary;82
7.6;Chapter 6: Working with Databases;83
7.6.1;The Basics of MySQL Data Storage;83
7.6.2;Manipulating Data with SQL;85
7.6.3;Developing a Database for the Poll;86
7.6.3.1;Creating a Database Using CREATE;86
7.6.3.1.1;The CREATE TABLE Statement;87
7.6.3.1.2;Understanding PRIMARY KEY;89
7.6.3.1.3;Understanding AUTO_INCREMENT;90
7.6.3.2;The INSERT Statement;90
7.6.3.3;The SELECT Statement;91
7.6.3.4;The UPDATE Statement;92
7.6.4;Coding a Database-Driven Site Poll;92
7.6.4.1;Separating Concerns with MVC;92
7.6.4.1.1;Planning the PHP Scripts;93
7.6.4.2;Creating the Poll Project;94
7.6.4.3;Making a Poll Controller;95
7.6.4.4;Making a Poll Model;95
7.6.4.5;Making a Poll View;96
7.6.4.6;Hooking Up Poll View with Poll Model;96
7.6.4.7;Coding Is Like Playing the Blues;97
7.6.4.8;Connecting to MySQL from PHP;98
7.6.4.8.1;PHP Data Objects (PDO);98
7.6.4.8.2;Opening a Connection;98
7.6.4.8.3;Using a try-catch Statement;99
7.6.4.9;Using Constructor Arguments;100
7.6.4.10;Sharing the Database Connection with the Poll Model;102
7.6.4.11;Retrieving Data with a PDOStatement;103
7.6.4.12;PDO and PDOStatement Objects;103
7.6.4.12.1;The PDOStatement’s fetchObject(?) Method;104
7.6.4.13;Showing a Poll Form;104
7.6.4.13.1;Triggering a Custom Error Message;105
7.6.4.14;Updating a Database Table According to Form Input;105
7.6.4.14.1;Responding to User Input;106
7.6.5;Summary;107
8;Part II:A Blogging System;108
8.1;Chapter 7: Building the Entry Manager;109
8.1.1;Creating the blog_entry Database Table;109
8.1.2;Planning the PHP Scripts;110
8.1.3;Creating the Blog Site;111
8.1.3.1;Creating the Entry Manager Navigation;112
8.1.3.2;Loading Admin Module Controllers;113
8.1.3.3;Creating the Entry Input Form;114
8.1.3.4;Styling the Editor;115
8.1.3.5;Connecting to the Database;117
8.1.3.6;Using Design Patterns;117
8.1.3.6.1;The Table Data Gateway Design Pattern;118
8.1.3.7;Writing the Entry_Table Class;118
8.1.3.8;Processing Form Input and Saving the Entry;119
8.1.3.8.1;Which Button Was Clicked?;120
8.1.3.8.2;Security Alert: SQL Injection Attacks;121
8.1.3.8.3;Usability Alert: Blog Entries with Quote Characters;121
8.1.3.8.4;Solution: Prepared Statements;122
8.1.4;Summary;123
8.2;Chapter 8: Showing Blog Entries;124
8.2.1;Creating a Public Blog Front Page;124
8.2.1.1;Creating a Blog Controller;125
8.2.1.2;Getting Data for All Blog Entries;125
8.2.1.2.1;Using an SQL SUBSTRING Clause;127
8.2.1.2.2;Using an SQL Alias;127
8.2.1.2.3;Testing Your Model;127
8.2.1.2.4;Using print_r() for Inspecting an Object;128
8.2.1.3;Preparing a View for All Blog Entries;129
8.2.1.4;Hooking Up View and Model;130
8.2.1.5;Responding to User Requests;130
8.2.1.6;Getting Entry Data;132
8.2.1.7;Creating a Blog View;132
8.2.1.8;Displaying an Entry;133
8.2.1.9;Code Smell: Duplicate Code;133
8.2.1.9.1;Staying DRY with Curly;134
8.2.1.9.2;Refactoring with Curly;134
8.2.1.10;Using the Private Access Modifier;137
8.2.2;Summary;138
8.3;Chapter 9: Deleting and Updating Entries;139
8.3.1;Creating a Model for Administrative Links;139
8.3.1.1;Displaying Administrative Links;140
8.3.1.2;Populating Your Form with the Entry to Be Edited;141
8.3.1.3;Handling Entry Deletion;143
8.3.1.4;Deleting Entries from the Database;143
8.3.1.5;Responding to Delete Requests;144
8.3.1.6;Preparing a Model to Update Entries in the Database;145
8.3.1.7;Controller: Should I Insert or Update?;146
8.3.1.8;Communicating Changes;147
8.3.1.8.1;Step 1: Update Model;147
8.3.1.8.2;Step 2: Update Controller;148
8.3.1.8.3;Step 3: Update View;150
8.3.1.9;Insisting on a Title;151
8.3.1.10;Improving Editor Usability with Progressive Enhancement;152
8.3.1.11;Embedding Your External JavaScript;153
8.3.1.12;Showing a Warning If Title Is Empty;154
8.3.1.13;Other Usability Flaws;156
8.3.1.14;A Coding Challenge: Fix a Usability Flaw;156
8.3.2;Summary;157
8.4;Chapter 10: Improving Your Blog with User Comments and Search;158
8.4.1;Building and Displaying the Comment Entry Form;158
8.4.1.1;A Combined View;159
8.4.1.2;Creating a Comment Table in the Database;161
8.4.1.3;Using a Foreign Key;162
8.4.1.4;Building a Comment_Table Class;162
8.4.1.5;Staying DRY with Inheritance;163
8.4.1.6;Is-a Relationships;165
8.4.1.7;Using Inheritance in Your Code;165
8.4.1.8;Inserting New Comments into the Database;166
8.4.1.8.1;Testing the saveComment() Method;167
8.4.1.9;Retrieving All Comments for a Given Entry;168
8.4.1.9.1;Testing getAllById();168
8.4.1.9.2;Creating a View for Listing Comments;169
8.4.1.9.3;Hooking Up View and Model to Display Comments;170
8.4.1.10;Inserting a Comment Through the Comment Form;170
8.4.1.11;Practice Makes Perfect;171
8.4.2;Searching for Entries;172
8.4.2.1;The Search View;172
8.4.2.2;Responding to a User Search;173
8.4.2.3;The Search Model;174
8.4.2.3.1;Searching with a LIKE Condition;175
8.4.2.3.2;Test Model;175
8.4.2.4;A Search Result View;176
8.4.2.5;Loading a Search Result View from the Controller;177
8.4.2.6;Exercise: Improving Search;177
8.4.3;Summary;177
8.5;Chapter 11: Adding Images to Blog Entries;178
8.5.1;Problem: Cannot Delete an Entry with Comments;178
8.5.1.1;Understanding Foreign Key Constraints;179
8.5.1.2;Deleting Comments Before Blog Entry;179
8.5.2;Improving Usability with WYSIWYG;180
8.5.2.1;Integrating TinyMCE;180
8.5.3;Creating an Image Manager;182
8.5.3.1;Showing a Form for Uploading Images;183
8.5.3.2;A Quick Refresher on the $_FILES Superglobal Array;184
8.5.3.3;Uploading an Image;185
8.5.3.4;What Could Possibly Go Wrong?;186
8.5.3.4.1;Updating the Uploader Class;186
8.5.3.4.2;Error: Restrictive Folder Permissions;187
8.5.3.4.3;Error: Upload File Too Big;189
8.5.3.4.4;Configuring via ini.php or .htaccess;190
8.5.3.4.5;Detecting Other Errors;191
8.5.3.4.6;Further Refinements;192
8.5.4;Displaying Images;193
8.5.4.1;Deleting Images;194
8.5.5;Using an Image in a Blog Entry;196
8.5.5.1;Improving Editor Usability;196
8.5.6;Summary;200
8.6;Chapter 12: Password Protection;201
8.6.1;Creating an admin_table in the Database;201
8.6.1.1;Encrypting Passwords with MD5;202
8.6.1.2;One-Way Encryption;202
8.6.1.3;Sufficient Security;202
8.6.1.4;Adding Administrators in the Database;203
8.6.2;Building an HTML Form;203
8.6.3;Saving New Administrators in the Database;204
8.6.4;Planning Login;205
8.6.4.1;Creating a Login Form;206
8.6.4.2;Hiding Controls from Unauthorized Users;207
8.6.4.3;Logging In a User;208
8.6.4.3.1;HTTP Is Stateless;208
8.6.4.3.2;Superglobals Revisited: $_SESSION;209
8.6.4.3.3;Persisting State with a Session;209
8.6.4.4;Logging Users Out;210
8.6.4.5;Allowing Authorized Users Only;211
8.6.4.6;Exercises;212
8.6.5;Summary;213
8.7;Chapter 13: Going Public with Your Blog;214
8.7.1;Web Host Requirements;214
8.7.2;Exporting and Importing Your Database;214
8.7.3;Preparing Your PHP Files for Upload;216
8.7.3.1;Uploading Files with FileZilla FTP;216
8.7.4;Summary;217
9;Index;218


Jason Lengstorf is a 27-year-old turbogeek from Portland, OR. He started building websites in his late teens when his band couldn t afford to pay someone to do it, and he continued building websites after he realized his band wasn t actually very good. He s been a full-time freelance web developer since 2007, and expanded his business under the name Copter Labs, which is now a distributed freelance collective, keeping about 10 freelancers worldwide busy. He is also the author of PHP for Absolute Beginners and Pro PHP and jQuery.



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.