1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Beginning PHP4 P1 doc

40 464 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 40
Dung lượng 710,82 KB

Nội dung

Beginning PHP4 Wankyu Choi Allan Kent Chris Lea Ganesh Prasad Chris Ullman with Jon Blank Sean Cazzell Wrox Press Ltd.  Beginning PHP4 © 2000 Wrox Press All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Published by Wrox Press Ltd, Arden House, 1102 Warwick Road, Acocks Green, Birmingham, B27 6BH, UK Printed in the United States ISBN 1861003730 Trademark Acknowledgements Wrox has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee the accuracy of this information. Credits Authors Technical Reviewers Wankyu Choi Luis Argerich Allan Kent Darren Beale Chris Lea Mark Fehrenbacher Ganesh Prasad Dario Ferreira Gomes Chris Ullman Chris Harshman Andrew Hill Contributing Authors Mark Mamone Jon Blank Jurgen Prins Sean Cazzell Mark Roedel Bart Ssyszka Additional Material Rick Stones Simon Cozens Travis Swicegood John Kauffman Kevin Yank Dan Squier Production Manager Technical Architect Laurent Lafon James Hart Production Project Co-Ordinator Technical Editors Pip Wonson David Mercer Christian Peak Figures/Illustrations Dan Squier Shabnam Hussain Julia Gilbert Mark Waterhouse Cover Shelley Frazier Category Manager Viv Emery Chapter Divider Dan Squier Author Agent Lynne Bassett Proofreaders Fiona Berryman Index Odette Randall Alessandro Ansa Project Administrator Nicola Phillips About the Authors Wankyu Choi Wankyu holds a Master's degree in English/Korean interpretation and translation from the Graduate School of Translation & Interpretation. He is the president/CEO of NeoQuest Communications, Inc. running a PHP- powered English language education portal (http://www.neoqst.com) in the Republic of Korea. He is independently working on an open source PHP project called NeoBoard (http://www.neoboard.net), a feature-rich web discussion board. I'd like to thank my parents for their encouragement and guidance, the dedicated staff at Wrox and technical reviewers for all their hard work, the staff at NeoQuest for their support while working on the book, and last but not the least, my wife, Yonsuk Song for her patience and love for this particular computer nerd. Allan Kent Allan has been programming seriously for the last 7 years and other than the single blemish when he achieved a Diploma in Cobol programming, is entirely self-taught. He started his career working at the local University and now runs his own company. Allan lives in Cape Town, South Africa with his girlfriend and 5 cats. Chris Lea Chris is one of the co-founders of Lucid Designs (http://www.luciddesigns.com), a Venice, CA based web design and development firm. He received a BS in Physics with Highest Honors and Distinction from UNC- CH in 1997, and has been hacking away with lots of (mostly open source) software since then. During his tenure with Lucid, he has worked on a wide variety of web site development projects ranging from the entertainment industry to the financial sector. When he's not staring at his monitor, you can usually find him swing dancing somewhere in the Los Angeles area. For more information, you can always check out his personal site at http://www.chrislea.com/. Ganesh Prasad Ganesh has worked in IT for 13 years, specializing in applications software design and development, in a number of countries including India, the United Arab Emirates, and Australia. He currently works for Reply2 Ltd., Australia, an e-CRM service provider. His experience covers IBM mainframes, VAX and UNIX minis, as well as Windows client/server and Web-based programming. Interests include Java and Open Source software, and his hope is that Open Source software will bring cheap computing to the masses and kick-start Third World economies. He is an Australian citizen, and lives in Sydney with his wife Sashi and son Lalit. I'd like to thank my wife Sashi for her patience, support and encouragement. She took all my other responsibilities off my shoulders, allowing me to concentrate on the task of writing. Chris Ullman Chris Ullman is a Computer Science graduate who came to Wrox five years ago, when 14.4 modems were the hottest Internet technology and Netscape Navigator 2.0 was a groundbreaking innovation. Since then he's applied his knowledge of HTML, server-side web technologies, Java, and Visual Basic to developing, editing, and authoring books. When not trying to reconstruct the guts of his own PC or trying to write extra chapters in a hurry, he can be found either playing keyboards in psychedelic band, The Bee men, tutoring his cats in the way of eating peacefully from their own food bowl and not the one next to theirs, or hoping against hope that this is the year his favorite soccer team, Birmingham City, can manage to end their exile from the Premier League. Thanks to James and Sarah B for getting me involved on this project and Christian, David, and Dan for deciphering, organizing, and improving my work, and most importantly thanks to my wife Kate, for being there. Jon Blank Jon Blank has been a part of the Linux world since before "Linux" was a buzzword, and has been programming (much to the detriment of his social life) in various languages for the better part of his life. He came to the PHP world by way of Perl, and came to Perl by way of The Web Union, an experimental Web hosting provider for students and non-profit organizations that he runs in his spare time. He currently lives in the New York City area, where he is trying to craft a stable career in a field where tempting offers are always around the corner. He doesn't think he'll succeed. Jon's interests include online role-playing, vintage computers and video games, and graphics arts, as well as many sorts of programming. His primary focus as a programmer is on automation – convincing the computer to do the sort of boring and/or repetitive work that only a computer can stand. Table of Contents Introduction 1 Why PHP4? 2 The Prompt 2 What Do I Need To Use This Book? 3 PHP4 Resources 4 Conventions 4 Downloading the Source Code 5 Support & Errata 5 Online Forums at p2p.wrox.com 6 Checking the Errata Online at www.wrox.com 6 Wrox Developer's Membership 6 Finding Errata on the Web Site 8 Adding Errata and Obtaining e-Mail Support 9 Customer Support 9 Editorial 9 The Authors 9 What We Can't Answer 9 How to Tell Us Exactly What You Think 9 Chapter 1: Installation 11 Installing PHP4 on Windows 95 and 98 13 Obtaining PWS 13 Setting Up PWS 15 Installing PHP4 Alongside PWS 17 Installing PHP4 on Windows NT and 2000 19 Installing PHP4 Alongside IIS 24 Installing PHP4 on Linux and Other UNIXes 28 Choosing Your Installation Method 29 Obtaining RPMs 29 Which Packages Do We Need? 30 Configuring and Starting Apache with PHP4 31 ii Testing Your Installation 34 iii Chapter 2: Writing PHP Programs 39 An Example PHP Program 40 Viewing a Web Page 44 Client-Server 44 Internet Protocols 44 The HTTP Protocol 45 The HTTP Request 46 The HTTP Response 48 Where PHP Comes Into This 49 Server-Side Scripting 50 Identifying a PHP Script 51 Caching 51 Variables 52 Data Types 55 String Data Type 55 Numeric Data Types 58 Constants 63 The Define Keyword 64 Initialization 64 Conversions 65 Type Casting 67 gettype and settype 67 isset, unset, and empty 68 Environment Variables 68 Summary 69 Chapter 3: Getting Data from the Client 71 Web Forms 72 The FORM Tag 72 Attributes of FORM 72 ACTION 72 METHOD 73 HTML Form Controls and PHP 76 Text Fields (Text Boxes) 76 Text Areas 80 Check Boxes 82 Radio Buttons 88 List Boxes 91 Hidden Controls 95 Passwords 99 Submit Buttons and Reset Buttons 99 Using Values Returned From Forms In Your PHP Scripts 100 Summary 106 Chapter 4: Decision Making 109 Conditional or Branching Statements 110 An Example of Branching in Day to Day Life 110 If Statements 111 Boolean Values 112 [...]... can run most PHP4 code, without alteration, on computers running many different operating systems A PHP4 script that runs on Linux will generally run on Windows as well ❑ HTML-embedded PHP4 code is written in files containing a mixture of PHP instructions and HTML code ❑ Server-side The PHP4 programs we write are run on a server – specifically, a web server ❑ A web scripting language We run PHP4 programs... techniques along the way, and we'll hopefully give you some ideas that you can incorporate into your own applications Why PHP4? One of the best things about PHP4 is that it is supported by a large number of Internet Service Providers (ISPs), which means that once you've written an application in PHP4, you can easily put it on the Web for anyone to use You can find a list of ISPs who can help you with hosting... the book on a single machine, acting as both client and server 3 PHP4 Resources Your first stop for information should be the official PHP site, which you can find at www.php.net This not only features news, downloads, and complete documentation (including user feedback), but it also features a complete searchable index of all the above PHP4 is based on the Zend scripting engine, owned by Zend Technologies,... and that's where PHP4 comes in So what sort of things can we do with it? Well, we can program sites that will: ❑ Present data from a wide variety of different sources, such as databases, or files ❑ Incorporate interactive elements, such as search facilities, message boards, and straw-polls ❑ Allow the user to perform actions, such as sending e-mail, or buying something In other words, PHP4 can be used... administrators to then send out e-mails to the subscribers So, PHP4 can be used for a diverse range of applications, from utilities like the text editor, to powerful web sites such as the shopping mall and directory examples In this book, we're going to try and equip you with the necessary knowledge to build any kind of web site you want using PHP4 You'll learn some useful coding techniques along the way,... 755 xix xx Introduction PHP4 is the latest incarnation of PHP – the "PHP Hypertext Preprocessor" It's a programming language for building dynamic, interactive web sites, originally devised by Rasmus Lerdorf way back in 1994 Since then it's been through a great many changes, and has been adopted by web programmers all around the world So what exactly is it? In technical terms, PHP4 is a cross-platform,... -+ What Do I Need To Use This Book? We will be focusing on using PHP4 on Windows and UNIX platforms As we shall see in the first chapter, we can install it on Windows 95 and 98, and NT and 2000 It will also run on virtually any flavor of UNIX, although our instructions only detail installation from RPM files As well as the actual PHP4 libraries, you'll need a text editor to create and edit your scripts... the User – HTTP, HTML, PHP and Interactivity Native Sessions in PHP4 218 221 224 227 228 228 228 228 229 229 232 232 235 235 236 237 237 238 239 239 240 241 241 242 243 243 243 244 255 256 257 257 257 258 258 261 262 262 264 'Do It Yourself' Persistence 265 Hidden Form Fields Revisited Query Strings Cookies 265 272 280 Sessions 287 vii PHP4 Sessions Summary viii 288 292 Chapter 9: Objects 295 Object-Oriented... the above PHP4 is based on the Zend scripting engine, owned by Zend Technologies, whose site can be found at www.zend.com Here you'll find information specific to PHP4, as well as articles, case studies, and news about the different uses PHP4 is currently being put to in business environments Another very useful resource is the www.phpbuilder.com site, a community-driven forum for PHP programmers It's... can get to any book's page by clicking on Support from the top navigation bar Halfway down the main support page is a drop down box called Title Support Simply scroll down the list until you see Beginning PHP4 Select it and then hit Errata This will take you to the errata page for the book Select the criteria by which you want to view the errata, and click the Apply criteria button This will provide . Beginning PHP4 Wankyu Choi Allan Kent Chris Lea Ganesh Prasad Chris Ullman with Jon Blank Sean Cazzell Wrox Press Ltd.  Beginning PHP4 © 2000. PHP4 on Windows 95 and 98 13 Obtaining PWS 13 Setting Up PWS 15 Installing PHP4 Alongside PWS 17 Installing PHP4 on Windows NT and 2000 19 Installing PHP4

Ngày đăng: 23/12/2013, 01:16

w