p. 1
the web book how to create web sites and applications with html css javascript php and mysql by robert schifreen d this file last updated 03 september 2010
[close]
p. 2
the small print please read this e-book is free of charge you can use it to help you develop sites for yourself or for anyone else you can also use it as a class textbook or as training material or place printed copies as many as you wis h in your school college university or company library you may not share the pdf file or upload it to online services if your friends colleagues or students want their own copy please direct them to www.theweb-book.com to download it if you are an internet service provider web hosting company or similar you are more than welcome to direct your users to www.the-web-book.com as a source of doc ument ation on how to create and maintain web sites producing derivative works is forbidden you may not create your own version of this book regardless of whether a fee is charged in addition you may not create a web site the content of which is wholly or partly based on text extracted from this book the web book is published by oak worth business publishing ltd registered in the uk company number 2783266 all content copyright © robert schifreen the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 2
[close]
p. 3
contents contents 3 about the web book 8 our recommended hosting companies 9 who s written this book and why 9 why we re here 10 from word processor to web site 13 but how long will all this take 14 what is a web site anyway 15 how the web works 15 domain names 16 the simple option 20 the flex ible option 21 about web content 24 do you need a development server 25 getting everything together 26 dom ain nam e and hosting 28 it s not rude to point 35 some more about hosting 37 shared hosting 37 reseller hosting 38 dedicated servers 38 v irtual servers 39 shared hosting signup with site5 40 ht ml editor and ft p client 46 amay a 47 make a web work folder 47 filezilla 47 your first web page with hostmonster 51 your first page with site5 56 now step away from the com puter 59 www what why who 59 importing ex isting content 60 writing for the web 61 fonts and colours 62 hyperlinks 63 linking to other sites 65 mailto links 65 understanding the basics of ht ml 67 meta tags 7 0 html accessibility accuracy and privacy 71 the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 3
[close]
p. 4
v alidating your html 71 a bit more about accessibility 7 2 cascading style sheets 74 about docty pes 7 5 getting started with css 7 5 a word about fonts 82 classes 84 making sty les work for you 85 html tags names 86 a better css editor 86 id-based sty les 89 ex treme css 90 page layouts and div tags 93 the css box model 98 pictures on pages 99 about image sizes 100 pictures as links 101 finding images to use on your site 102 a browser icon for your site 103 short cuts to great web pages 107 using an open source design 109 tweaking the text 110 changing the pictures 111 changing the css sty les 112 which sty le is this 114 adding pages and nav igation 116 uploading the finished files 120 rules t ables and image maps 122 horizontal rules 122 tables 124 image maps 126 password-protecting your web pages 129 the .htaccess file 129 the .htpasswd file 131 protecting multiple folders 133 cmses and other software 134 cmses and templates 136 automatic installers 137 try before you install 138 a word about patching 140 setting up a database 140 general installation procedures 143 uninstalling 143 joomla 145 uploading the files 145 the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 4
[close]
p. 5
configuring joomla 146 your new joomla site 152 wordpress 157 downloading the software 157 make a database 157 configure wordpress 157 upload the software 159 final configuration 159 phpbb 164 file permissions 165 plogger 172 getting started 17 2 the installation process 17 4 uploading your pictures 17 6 avoiding data overload 17 8 installing the pspad editor 180 jav ascript 184 choose your side 1 84 jav ascript and semicolons 192 email address obfuscation 192 why upload 193 security and cookies 194 morning all 196 getting the screen size 197 jav ascript toolkits and frameworks 197 finding out more 198 web-hosted databases with my sql 200 databases tables fields rows and columns 201 normalization 201 referential integrity 204 creating a database 205 port problems 208 using phpmyadmin 210 creating the customers table 211 inserting some data 21 6 query ing the customers table 21 9 introducing php 228 don t panic 228 your first php program 229 some more php 236 random numbers 236 sending email with php 240 passing information to php 243 nev er forget to sanitize 245 loop the loop 248 the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 5
[close]
p. 6
arrays 251 user-defined functions 255 ht ml forms 257 creating a form with amaya 259 naming the form objects 262 handling form data and quote marks 265 testing the form 267 retriev ing tex tarea and dropdown data 27 0 checkbox array s 27 1 feedback forms 27 3 hidden fields 27 4 accessing my sql databases with php 276 counting rows 27 8 reading data 280 searching a table 285 preventing sql injection attacks 290 adding data to a table 291 editing a data record 298 deleting data 305 putting it all together 306 debugging and global variables 308 sy ntax errors 308 coding errors 309 the serv er v ariables 313 application structure rev isited 316 web serv ers and the real world 317 sav ing state 31 8 how to back up y our web site 319 don t forget the data 31 9 restoring lost information 322 prom oting and profiting 323 promoting your site 323 making money 325 accepting online pay ments 327 managing your marketing 330 search engine optimisation 334 seo tips 334 keeping the crawlers away 336 if at first you don t succeed pay 337 the end so what now 339 appendix a building a t est serv er 340 our goal 340 first install the os 341 some useful commands 342 get updated 343 the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 6
[close]
p. 7
test your web server 344 install the telnet server 344 an ftp server 345 webmin 347 webalizer 348 php and my sql 349 the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 7
[close]
p. 8
about the web book if you want to create web sites there are hundreds of books and web pages that claim to show you how some of them are very good indeed but this book isn t like all those other books and web pages for a number of important reasons 1 the web book is an electronic book or e-book you simply download it as a pdf file from www.the-web-book.com and print it yourself or read it on-screen 2 the web book covers all of the technologies that you need to know in order to create web sites both using static html pages and database-driven sites 3 unlike many books on the subject that were written some years ago the web book teaches you up-to-date methods follow the instructions here and you can be confident that you re doing things in the right way rather than using old-fashioned techniques that are now frowned upon 4 i ve tried my hardest to keep everything non-technical if you re into computers you should be able to follow everything just fine you certainly don t need to be a professional techie in fact if you are you ll probably take offence at the way i ve simplified some things for which i apologise 5 if you already look after a web site perhaps for your school or college or the department you work for you may be itching to take your skills to the next level or maybe you didn t actually get much training when you took on the responsibility and you don t really understand how everything fits together in which case this book is perfect for you we don t just tell you to press buttons we explain what those buttons do and why you need to press or not press them 6 here s the best bit the web book is free of charge so if you want to teach yourself how to do web stuff whether for creating your own sites or to make sites for other people just grab a copy of the pdf file print out the book and away you go one word of warning though creating a web site and doing it properly isn t a simple task that can be done in an afternoon y es we ve all seen 2-page magazine articles that imply otherwise but sadly it s just not true even at 350 pages this book is only a basic introduction to some of the more complex topics it s quite possible to buy books on html css php and mysql which each run to 800 pages i wouldn t recommend it however unless you have trouble sleeping the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 8
[close]
p. 9
our recommended hosting companies if you want to create a web site you need a company to host it for you there are thousands of such companies out there just type web hosting into a search engine and you ll find them the examples in this book are based around a handful of hosting companies that i personally recommend i use these companies for my own sites and they ve never let me down if you re looking for a decent web host i d love you to use one of the companies featured in these pages firstly because i happen to think they re pretty good and secondly because i will get a small amount of commission from the company when you sign up that s what funds the continuing development of this free book which took me 5 solid months to write to sign up with one of the recommended hosts just go to www.the-web-book.com/hosting and click on any of the links or adverts on that page thank you who s written this book and why the web book is written by robert schifreen a uk-based journalist writer and technical author i have more than 25 years experience of writing all sorts of technical articles for various computer magazines and 9 years experience developing web sites for myself and clients i ve also written a traditional book before that was published in 2006 and was available as a real hardback in real bookshops a google search for defeating the hacker will find it for you having taught web development to the 2,500 staff at a uk-based university for the past few years i thought it might be helpful to turn my course into a book which is loosely based on the stuff i teach and is also inspired by the questions that my students ask from now on when people ask me how to create a web site or whether it s easy i don t have to spend time explaining everything i can just say go to www.the-web-book.com and download my free book which tells you everything you need to know this is the book which i really wish had existed when i started doing web stuff all those years ago but you re probably asking why am i giving it away instead of selling it there are 3 reasons one i quite like the idea of being able to write what i want for a change without having publishers and editors to answer to the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 9
[close]
p. 10
two i want as many people as possible to see this book because i think it s genuinely useful the trouble with traditional publishing is that of the hard-earned money that you hand over to pay for a copy of a traditional book most of it is swallowed up by the publishers and their marketing costs the author the guy who sat in front of his pc for months writing the thing typically gets around 15 of your cash sometimes less so i ve decided to try something different this book is free to download and use it is financed in 2 ways · · you can make a donation at www.the-web-book.com/donate if you sign up with one of the hosting companies mentioned at www.the-webbook.com/hosting i get a small commission payment it won t cost you any more to sign up in that way but it means a lot to me and the third reason why i m giving away the book having been a professional it journalist editor and writer since 1983 i ve seen what the internet is doing to the publishers of magazines and books especially those companies which produce it-related publications computer magazines across the world are being shut down and book sellers are having a hard time because the web not the pages of a book is undoubtedly the best place to find information about technical subjects in many cases those publications shut down not because the product was poor but because the publishers failed to see the internet coming and failed to act accordingly publishers need to work with the internet not against it sure a search engine means that i can find an answer to a technical problem instantly without having to plough through shelves of books and magazines but the web is also the greatest biggest best cheapest and most efficient way of copying and disseminating information that s ever been invented just ask the music industry so by promoting this book on the internet as a free download i hope that i can exploit the power of the internet rather than trying to work against it why we re here no one could have believed in the last years of the 20th century that the way we d all been doing web sites was about to change so dramatically but it did in two fundamental ways firstly web sites generally consisted of a collection of html document files each page of the site was a separate file don t worry if you don t understand much of what i m saying here everything will be explained more fully shortly while this works for relatively simple sites with just a few pages there are better ways to create web sites using database technologies such as mysql and programming languages such as php you can create not just simple informational web sites that allow you to publish information but two-way sites that allow your visitors to interact stop thinking electronic newspaper and think facebook or ebay or amazon the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 10
[close]
p. 11
the second major change was in the fundamental way that web pages were structured in terms of layout and formatting font tags gave way to something called css or cascading style sheets in a nutshell creating web sites has become vastly more complicated over the past decade you ll see from the front cover that this book covers html css javascript php and mysql if you re daunted by all that then don t be we ll cover everything in a logical order building up your knowledge in layers so that all the new material you learn will make perfect sense because you ll be able to see it in context you are of course free to dip into the book as you wish reading sections in whatever order pleases you if you want to know what php or mysql is all about then by all means skip straight to those chapters but if you can possibly spare the time you ll find it much more beneficial to read everything in order it ll make much more sense in the long run of course you may not actually need this book at all if all you want to do is to put some information online as quickly as possible so that other people can access it over the web there are plenty of free services out there that will allow you to do this quickly and easily among the best-known of these services are www.myspace.com a social networking site especially good if you want to upload pictures and music rather than text www.facebook.com the best-known social networking site where you can post information about yourself www.wordpress.com if you want a blog but you don t want to run your own version of the wordpress blogging software this site will host a blog for you just sign up for free on the web www.blogger.com another blogging site which is free to use owned by google if you want a personal blog with the minimum of fuss then using this site or wordpress.com is by far the easiest way to do it sites.google.com create text-based pages and publish them online for free courtesy of google www.flickr.com the best-known place to upload your photos and share them with the world www.youtube.com does for video what flickr does for stills upload 10-minute clips of just about anything docs.google.com google s web-accessible word processor and spreadsheet use it just for yourself or share documents with friends for collaborative editing spaces.live.com free web space for you publish a blog pictures music or whatever the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 11
[close]
p. 12
www.twitter.com you like from microsoft the micro-blogging site where you can tell everyone what you re up to before you read any further you may want to consider signing up with one or more of these systems even if only to gain some inspiration into what your own site should or shouldn t look like another option is to sign up with a site that offers an easy automated way to create web pages many hosting companies offer such things thus making it easy to create pages on the hosting space that you ve just bought among such offerings are easy website creator from leading hosting company 1&1 the design selection screen of which looks like this just pick a design and a colour scheme type in some text and you have a web site another example of the genre is from uk-based hosting company easily.co.uk their design selection screen is shown below the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 12
[close]
p. 13
once again choose a design and just start typing although these systems allow you to create a web site quickly and easily they are very limited if you want javascript php and mysql you re normally unable to add it you can t easily make major changes to the design and you re frequently limited to just 20 or 30 pages depending on which hosting package you sign up for sometimes the figure is as low as just one page from word processor to web site there s yet another way to create web pages and that s to write the text with a word processor such as microsoft word or openoffice writer and then use the save as web page feature to create files which you can put online this is often a tempting option because a it looks to be very easy and b lots of people write documents with a word processor and then realise that they d actually quite like to publish them online the trouble is the save as web page feature in microsoft word including the most recent version is horrible it produces pages which contain ten times as much information as is strictly necessary which means that they ll take up ten times the space on your server take your visitors ten times as long to download and cost people ten times as much if they re accessing your site via mobile broadband or some other metered or pay-per-megabyte connection seriously don t do it if you do have some word documents that you want to put online there are some excellent third-party products available to do the conversion for you my favourite is click to convert which is what i use to create the web-based preview version of this book all of the the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 13
[close]
p. 14
pages in the online preview are automatically generated from a master microsoft word document in just a couple of minutes if you ve bought a hosting package and a domain name and you re not quite sure what to do with it one of the quick-start pages as mentioned above is better than nothing at all but if you really want to make the most of the web there really is no substitute for learning how to do it properly and that s what you ll do if you continue reading but how long will all this take i do hope that you decide to read this book all the way through and follow the examples in it remember that this is a textbook rather than a novel by all means read through it in a day or two but you won t get the best from it for that you need to work through it gradually at your computer following the examples y ou should allow a week or 2 at least to get the greatest benefit maybe even a little longer if you want to experiment further and enhance some of the examples with your own ideas the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 14
[close]
p. 15
what is a web site anyway a web site is traditionally a collection of pages of information creating a web page is in many ways very similar to writing a letter with a word processor and saving it on your computer but there are a couple of important differences first you have to save the page in a special format ie language known as html rather than as a normal document html stands for hypertext markup language why hypertext that s the name given to the way that we move between web pages by clicking on hyperlinks those bits of text which are normally in blue and underlined a markup language is just a way of marking up text to specify that for instance when the visitor to our site clicks on home he gets taken to the home page the reason we have to save our pages in html format rather than as word documents excel spreadsheets pdf files zip files etc etc is that the way we read web sites is with a program called a web browser for example internet explorer firefox safari google chrome or opera the only type of information that web browsers are guaranteed to be able to display are html files sure if you put a word document on your web site or a pdf file some web browsers might make a good stab at displaying the file but it s never guaranteed to work the second difference between creating web pages and writing a letter is that having created your web page you obviously need to save it but rather than saving on your own computer where only you can see it you need to save it onto a web server a web server is simply a normal computer connected to the internet which runs a web server program this program means that other people s computers across the internet can connect to it request a copy of your page and display it in theory any computer that has a permanent connection to the internet can be turned into a web server just install the necessary software which is easily available free of charge and the job is done however hackers love breaking into web servers and crashing them or trying to change the contents of the pages they store so unless you really know what you re doing it s much easier and safer to rent some space on someone else s web server to store your web content rather than running your own server it s very cheap to do as we ll discover later how the web works the web book is free of charge see www.the-web-book.com to download the latest version to sign up with any of the web hosting companies featured in this book visit www.the-web-book.com/hosting it costs you just the same but brings me a small commission that funds the development of this book 15
[close]