Register · · Password forgotten? · |
Simon Mark / Саймон Марк - An Introduction
|
![]() |
Home » Books and magazines » Computer literature » Web design and programming |
DL-List and Torrent activity | |||||||||||||||
Size: 23 MB | Registered: 8 months 3 days | Completed: 2 times | |||||||||||||||
shows data only for the current session
|
|||||||||||||||
|
Author | Message | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Download WYSIWYG ® Gender: Longevity: 9 years Posts: 1513 |
An Introduction to PHP: Learn PHP 8 to Create Dynamic Websites / Введение в PHP: Изучите PHP 8 для создания динамических веб-сайтов
Год издания: 2024 Автор: Simon Mark / Саймон Марк Издательство: Apress Media LLC ISBN: 979-8-8688-0177-8 Язык: Английский Формат: PDF/EPUB Качество: Издательский макет или текст (eBook) Интерактивное оглавление: Да Количество страниц: 639 Описание: Use PHP to enhance your web pages. This book shows you how PHP programming works, and how to write and organize PHP code. The book starts with steps to download and install a setup for a sample website that will form the basis for upcoming chapters. You start by writing PHP code and learn how to mix it with HTML and manage the code. From there, you will learn about dynamic content, along with a deep dive into form processing and sending email. Saving uploaded data and uploading files is discussed next. You will learn how to configure your PHP project and develop a library. You will then learn how to create an image catalog and manage data on your web page. By the end of the book, you will understand how to work with cookies, sessions, and logging in, followed by an example of creating a simple blog that reiterates the concepts developed in the previous chapters. After reading this book, you will be able to configure, create, and manage your dynamic website. What Will You Learn Know the basics of programming with the PHP language Use PHP to generate dynamic web pages Work with SQL databases Work with forms to upload text data and binary files Use tips and tricks to write clean and maintainable code Who This Book Is For Web developers and students learning to develop and maintain PHP code on their website Используйте PHP для улучшения своих веб-страниц. В этой книге показано, как работает программирование на PHP, а также как писать и упорядочивать PHP-код. Книга начинается с инструкций по загрузке и установке примера веб-сайта, который ляжет в основу последующих глав. Вы начнете с написания кода на PHP и узнаете, как сочетать его с HTML и управлять кодом. Далее вы узнаете о динамическом контенте, а также познакомитесь с обработкой форм и отправкой электронной почты. Далее обсуждается сохранение загруженных данных и загрузка файлов. Вы узнаете, как настроить свой PHP-проект и разработать библиотеку. Затем вы узнаете, как создать каталог изображений и управлять данными на вашей веб-странице. К концу книги вы поймете, как работать с файлами cookie, сеансами и входом в систему, а затем приведете пример создания простого блога, который повторяет концепции, разработанные в предыдущих главах. Прочитав эту книгу, вы сможете настраивать, создавать и управлять своим динамическим веб-сайтом. Чему вы научитесь Познакомитесь с основами программирования на языке PHP Используйте PHP для создания динамических веб-страниц Работайте с базами данных SQL Работайте с формами для загрузки текстовых данных и двоичных файлов Используйте советы и рекомендации по написанию чистого и поддерживаемого кода Для кого предназначена эта книга Веб-разработчики и студенты, которые учатся разрабатывать и поддерживать PHP-код на своих веб-сайтах ОглавлениеAbout the Author ..............................................................................xviiAbout the Technical Reviewers .........................................................xix Acknowledgments .............................................................................xxi Introduction .....................................................................................xxiii Chapter 1: Introduction and Setting Up ................................................1 How the Web Works ..............................................................................................2 The Sample Project ...............................................................................................4 The Tools ...............................................................................................................5 A Coding Editor ................................................................................................6 Web Server Setup .................................................................................................7 Using the Virtual Hosts Applications ..............................................................10 Adding the Domain Name ..............................................................................11 Editing the httpd.conf File .............................................................................13 Adding a Virtual Host .....................................................................................15 Fixing the php.ini File ....................................................................................18 Configuring PHP ..................................................................................................21 Setting PHP Options ......................................................................................23 Some Useful Configuration Options ...............................................................24 The Project Configuration Files .....................................................................27 Finishing Up ........................................................................................................29 Chapter 2: Working with PHP .................................................................................31 Before We Start ...................................................................................................32 Grouping: Brackets and Friends ....................................................................32 Data Types .....................................................................................................33 How PHP Processes Files ....................................................................................34 Renaming the Files ........................................................................................35 PHP Scripts ....................................................................................................36 Adding Dynamic Data to the Page .................................................................39 Displaying Data .............................................................................................42 Including Files .....................................................................................................44 Preparing and Implementing Include ............................................................46 Headings and Titles .............................................................................................48 Including Variables in the Include Files .........................................................49 Setting the Title and Heading ........................................................................51 The Navigation Block ..........................................................................................51 The Links Array ..............................................................................................53 Creating the List of Links ...............................................................................54 Displaying the Links ......................................................................................58 Highlighting the Current Page .......................................................................59 Comments ...........................................................................................................62 Summary ............................................................................................................64 Coming Up ...........................................................................................................65 Chapter 3: Email and Form Processing .....................................................................67 Preparation .........................................................................................................68 The Contact Form ................................................................................................68 The Plan of Attack ..........................................................................................72 Reading the Form Data .......................................................................................73 Outlining the Plan ..........................................................................................75 Reading the Form Data .......................................................................................76 Preparing the Data .........................................................................................77 Persisting Fields ............................................................................................78 Form Validation ...................................................................................................80 JavaScript and HTML5 Validation ..................................................................80 Planning for Validation ...................................................................................81 Required Fields ..............................................................................................82 Checking an Email Address ...........................................................................84 Email Injection ...............................................................................................85 Handling the Errors ........................................................................................89 Sending Email with the mail() Function ..............................................................92 The Main Email Variables ..............................................................................93 The Email Headers ........................................................................................95 After Sending the Message .................................................................................99 Alternative Parts ............................................................................................99 Writing the Conditional Blocks ....................................................................102 Reorganizing the Code ......................................................................................104 Configuration ...............................................................................................104 Moving the Code ..........................................................................................105 Summary ..........................................................................................................106 Coming Up .........................................................................................................108 Chapter 4: Uploading Data and Files .....................................................................109 The Upload Form ...............................................................................................109 The File Input ....................................................................................................112 Settings .......................................................................................................113 Preliminary Coding ............................................................................................114 The Data Variables .......................................................................................114 Processing POSTed Data and Preliminary Validation ...........................................116 Image Validation ................................................................................................118 The $_FILES Array .......................................................................................118 Using File Data ............................................................................................119 Checking an Image File ...............................................................................122 Keeping the File ................................................................................................125 The File Name ..............................................................................................126 Lower Case ..................................................................................................128 Replacing Spaces ........................................................................................128 Defining the Location ..................................................................................129 Moving the File ............................................................................................131 Creating Additional Copies ................................................................................132 Resized Image Configuration .......................................................................134 Generating the Resized Copies ....................................................................135 Tidying Up .........................................................................................................136 Clearing the Error Array ...............................................................................136 Clearing the Old Values ................................................................................137 Summary ..........................................................................................................137 Coming Up .........................................................................................................138 Chapter 5: Working with a Database ....................................................................139 Something About Databases .............................................................................141 Running SQL ................................................................................................144 MySQL and PHPMyAdmin ............................................................................144 Browsing .....................................................................................................146 The Setup Page ...........................................................................................146 Creating the Database and User .......................................................................148 Preparing the Images Table .........................................................................151 Using the Database with PHP ...........................................................................153 Connection ...................................................................................................154 Connection String ........................................................................................154 Creating a Connection .................................................................................155 A Crash Course in Classes and Objects .......................................................156 Handling Connection Errors .........................................................................158 exit or die .....................................................................................................159 Adding Options ............................................................................................160 Setting the PDO Options ..............................................................................162 Using the Alternative Script .........................................................................163 Summary ..........................................................................................................163 Coming Up .........................................................................................................164 Chapter 6: Adding Data to the Database ..............................................................165 Connecting to the Database ..............................................................................166 SQL Injection .....................................................................................................167 Prepared Statements ...................................................................................169 When to Worry About SQL Injection .............................................................171 Adding the Image Data to the Table ..................................................................172 Line Breaks ..................................................................................................174 Creating Line Break Functions ....................................................................175 The Prepared SQL Statement ......................................................................179 Executing with Data ....................................................................................181 Retrieving the New ID ..................................................................................182 Modifying the Name ..........................................................................................183 Constructing the New Name ........................................................................184 Zero-Padding a Number ..............................................................................184 Updating the Database ................................................................................185 Keeping the File and Creating the Resized Copies ............................................186 Refactoring the Code ........................................................................................187 The Function Outline ...................................................................................187 Scope ...........................................................................................................189 Writing the addImageData() Function ..........................................................190 Writing the addImageFile() Function ...........................................................193 Using the Code in the Future .......................................................................196 Summary ..........................................................................................................196 Coming Up .........................................................................................................197 Chapter 7: File Handling .....................................................................................199 Preparation .......................................................................................................200 The ZIP File ..................................................................................................201 The CSV File .................................................................................................202 Processing the Uploaded Zip File ......................................................................203 Checking the Zip File ...................................................................................204 Unzipping the File ........................................................................................206 Reading Text Files ........................................................................................211 Importing the Data .......................................................................................217 Checking the MIME Types ............................................................................219 Finishing Up ......................................................................................................223 A Crash Course in HTTP(S) ..........................................................................224 Headers Already Sent ..................................................................................226 Redirecting to the Next Page .......................................................................227 Starting Over .....................................................................................................230 Summary ..........................................................................................................234 Coming Up .........................................................................................................235 Chapter 8: The Image Gallery ...............................................................................237 Preparation .......................................................................................................238 Fetching the Thumbnails ...................................................................................240 Fetching from the Database ........................................................................240 Fetching a Gallery Page ...............................................................................242 Fetching the Rows .......................................................................................246 Generating the Gallery Images ....................................................................248 Selecting the Page ......................................................................................252 The Navigation Block ...................................................................................258 Remembering the Page ...............................................................................263 Displaying a Larger Image ................................................................................267 Fetching a Miscellaneous Single Image ......................................................267 Selecting a Random Row from the Database ..............................................272 Fetching a Selected Image ..........................................................................274 Displaying a Random Image on Other Pages ....................................................277 Summary ..........................................................................................................281 Coming Up .........................................................................................................283 Chapter 9: Managing Data ..................................................................................285 The Image Pages ..............................................................................................286 The Image List Page ..........................................................................................291 Preparatory Code for the Image List ............................................................292 Something About HTML Tables ....................................................................294 Generating the Table Data ...........................................................................298 The Image Editing Page ....................................................................................305 The Prepare Events .....................................................................................306 Fetching the Data to be Edited ....................................................................309 Implementing Update and Delete ......................................................................315 Deleting Data ...............................................................................................316 Updating the Image Data .............................................................................319 Checking a Checkbox ........................................................................................325 Adding the Checkbox ...................................................................................326 Testing the Checkbox ..................................................................................329 Finishing Touches .............................................................................................333 Clearing the $id when Adding an Image ......................................................333 Fixing the Hidden Field ................................................................................334 Restoring the Images ..................................................................................334 Summary ..........................................................................................................335 Coming Up .........................................................................................................337 Chapter 10: Sessions and Logging In .....................................................................339 Sessions ............................................................................................................340 Session Settings ..........................................................................................341 Starting a Session .......................................................................................343 Using Session Data ......................................................................................346 Managing Users ................................................................................................348 Encryption and Hashing ..............................................................................349 Password Hashing in PHP ...........................................................................351 The User Table .............................................................................................352 Adding a User ..............................................................................................353 Logging In .........................................................................................................359 Processing Login .........................................................................................360 Successful Login .........................................................................................364 Switching Between Content ........................................................................365 Showing the User’s Name ...........................................................................367 Logging Out .......................................................................................................370 Restricting Access ............................................................................................371 Summary ..........................................................................................................374 Coming Up .........................................................................................................375 Chapter 11: A Configuration System ......................................................................377 The ini File Contents .........................................................................................377 Reading an ini File ............................................................................................380 Generating the Configuration Form ...................................................................385 Generating the Config Table ..............................................................................387 Saving the Configuration ...................................................................................392 Reading the New Values ..............................................................................392 Writing the ini File .......................................................................................394 Using the Configuration Settings ......................................................................396 Resizing Images ................................................................................................399 Adding Configuration to Administration ............................................................404 Summary ..........................................................................................................405 Coming Up .........................................................................................................406 Chapter 12: A Content Management System ...........................................................407 The Blog Pages .................................................................................................408 The Blog Table ...................................................................................................410 Preparatory Blog Code ......................................................................................413 Adding a Single Blog Article ..............................................................................418 Uploading the Optional Image ...........................................................................426 Checking for an Optional Image ..................................................................428 Keeping the Optional Image ........................................................................430 Previewing the Image ..................................................................................437 Selecting an Existing Image ........................................................................439 Selecting an Image from a Menu ................................................................440 Processing the Selected Image ...................................................................445 Previewing the Selected Image ...................................................................448 Selecting an Image from a Radio Group ......................................................450 Choosing Between Buttons and the Menu ..................................................455 Redirecting to the Blog List Page ................................................................456 Importing Blog Articles ................................................................................457 Changes to the Insert Code .........................................................................457 Starting the Import Code .............................................................................459 Handling the Import File ..............................................................................459 Copying the Blog Import Files ......................................................................462 Importing the Blog Data ...............................................................................464 Calling a Function with an Array of Parameters ................................................470 Finishing the Import ....................................................................................472 Reading a Blog Article .......................................................................................473 Preliminary Code .........................................................................................474 Getting the Selected Article ID .....................................................................476 Fetching the Article .....................................................................................478 Fixing the Article Line Breaks ......................................................................481 Displaying the Blog Image ...........................................................................483 Managing the Blog Articles ...............................................................................487 Building the Article Table .............................................................................492 Processing the Prepare Events ....................................................................495 Updating an Article ......................................................................................504 Deleting an Article .......................................................................................507 The Visitor Blog List ..........................................................................................509 Preparatory Code .........................................................................................511 Generating the Blog Article List ...................................................................513 Summary ..........................................................................................................516 Appendix A: Adding Markdown to Your Blog Articles ......................521 Appendix B: Non-PHP Tricks .............................................................535 Appendix C: PHP Versions ................................................................549 Appendix D: Default Library Functions .............................................557 Index .................................................................................................613
|
|||||||||||||||||||||
![]() |
Home » Books and magazines » Computer literature » Web design and programming |
Current time is: 24-Feb 14:39
All times are UTC + 2
You cannot post new topics in this forum
You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum |