Exercises, examples and other material relating to training module H112. This topic is presented on public courses
Applications often require a series of forms to be completed, with the final outcome being determined by the inputs from all the forms along the way. Furthermore, your web site may have several visitors filling in a series of forms at the same time. It's vital that you should be able to remember information from form to form, and also be able to tell your users apart from one another. This module covers the techniques used to "maintain state", and the PHP functions provided to help you do so.
Articles and tips on this subject | updated |
4483 | Moving from mysql to mysqli - simple worked example We have a big codebase of PHP code that uses MySQL databases, much of it written using mysql_ functions which were not object orineted in nature, and have been paralleled by the more recent mysqli_ functions and methods for quite some time now. The older mysql library is now deprecated, with warnings ... | 2015-05-03 |
4070 | Passing variable between PHP pages - hidden fields, cookies and sessions Variables within a program are lost when the program exits ... unless the program takes some sort of action to save them. And if it does, you've then got to have another program pick them up to use them somehow.
Web applications in PHP are a series of short-running programs. A program is run each time ... | 2013-04-27 |
789 | Hot answers in PHP We've got a lot - a LOT of demonstrations and source code on our site. Here are a few of the most popular ones all brought together in a single listing. Enjoy ...
Searching - how similar are two words? - try about source
Does a particular URL exist? - try source
Uploading an image to a database ... | 2013-01-02 |
3918 | Multiple page web applications - maintaining state - PHP As you want to do more in an online application, you need to link a series of forms together. There's a limit to how much you can expect your users to enter on one page, and almost inevitably they'll want feedback as they go through a series of steps. So multiple forms is natural, with each encouraging ... | 2012-11-17 |
3568 | Telling which ServerAlias your visitor used - useful during merging domains Someone tells you a website to visit - "go to wellhousemanor.co.uk" they say. And you'll naturally add "www." in front of it, calling up www.wellhousemanor.co.uk rather than wellhousemanor.co.uk ... or perhaps you won't.
Web servers are normally set up by default to respond to a single specific host ... | 2012-01-07 |
3540 | Easy session example in PHP - keeping each customers data apart When you go to a shop, you're not kept waiting outside until the previous customer leaves. The shop will have multiple shopping baskets / trollies, or muliple assistants. And that's the way you want it when you visit a web site too. This means that the web site programmer has to be very careful to ... | 2011-12-06 |
3432 | 3 digit HTTP status codes - what are they, which are most common, which should be a concern? We often talk during web related course / course modules about the status codes that are returned by servers - but I don't think I've ever written up a (near?) complete list. They are all three digit codes, and they're grouped by hundreds - so 200 series code are success, 400 codes are requests that ... | 2011-09-11 |
3036 | Sending out an email containing HTML from within a PHP page The mail function in PHP allows you to send a plain text email in a single function call from within your script but please read the cautions at the end of this post before you do so!. How do you send out something in HTML format, though?
The mail function takes an additional (fourth) parameter of extra ... | 2010-11-07 |
2918 | Downloading a report from the web for further local analysis There are many applications where users want to use a piece of web based software to explore data sets - to research information and come up with tables of results and lists of data which they then want to examine in more detail - explore further.
How do they do that further exploration - perhaps through ... | 2010-08-20 |
2729 | Uploading a document or image to its own URL via a browser One of the major requirements of a committee / working group such as the TransWilts Community Rail Partnership is to be able to share information - and a forum (such as Simple Machines) does that admirably. So after yesterday's meeting, I put up a forum for our initial work.
But one of the side issues ... | 2010-05-14 |
2679 | How to build a test harness into your PHP I was writing a PHP demonstration yesterday, and I wanted to include a test harness with my class definitions that I could leave in place on the live code on my server, to be silently skipped over ... but which I could re-use at a later date for testing class changes, etc.
How did I do it? An environment ... | 2010-03-16 |
2632 | Shipping a test harness with your class in PHP If you're writing a class (or group of classes) into a file you include into your main application(s) in PHP, you'll be recommended to keep the included files out of the document path so that they can't be run on their own (or, more dangerous, browsed as text if you have a different extension applied ... | 2010-03-05 |
936 | Global, Superglobal, Session variables - scope and persistance in PHP "Global" is a poor choice of word! It really means "share this variable in this function with the variable of the same name at the top level" but there isn't a simple, easy better word for that than "Global". If you bring in code within an include / require file, then any top level code's variables ... | 2009-01-01 |
356 | Sudoku helper or sudoku cheat Have you seen the sudoku puzzles that are being published in the Daily Telegraph and (I think) the Los Angeles times? There's a whole group of addicts out there and helper and forum web sites too. Lisa pointed the puzzle out to me recently (no, she's not an addict!) with the thought of providing a ... | 2008-06-06 |
425 | Caching an XML feed If you're using PHP to add a newsfeed to your site, please be kind to the news feed supplier and cache the feed if your page is a popular one. I posted a couple of weeks ago ... a link to a piece of code that grabs a news feed .... and I've enhanced it now to do the caching. Here's the modified code:
$feed ... | 2008-05-17 |
410 | Reading a news or blog feed (RSS) in your PHP page If you want to quote the latest articles from an RSS (XML based) news feed on your site, is it difficult? No - it can easily be programmed in PHP. I was exploring this yesterday and have the source code showing just how easy it is in our training resources.
Want to try it out? This link runs the ... | 2008-05-17 (short) |
1485 | Copyright and theft of images, bandwidth and members. Some poor home school kid in the USA just got the sharp end of my tongue .. I had just signed up to a political forum and so had he (he said) and he wrote:
Also I was wondering if you would join my political forum at http://www.xxx.org .(I know this is an advert but it's really hard to get a new board ... | 2008-05-10 |
345 | Spotting a denial of service attack Our web site traffic rose from 37000 hits last Wednesday to 64000 hits on Thursday. Good sales and marketing activity on our part? No - it's a potential problem; all the extra traffic came from a single location and my immediate concerns included:
* Possible denial of service, where all the bandwidth ... | 2008-05-04 |
1549 | http, https and ajp - comparison and choice In a web scenario, client to server traffic is usually carried using an http (HyperText Transfer Protocol) transport. That's both from browser to public facing server, but also in ongoing transfers from the public facing server to other servers which provide content or run business logic in many applications.
But ... | 2008-02-23 (longer) |
1518 | Downloading data for use in Excel (from PHP / MySQL) Requirement: To allow a visitor to your web site to click on a link that downloads data from the server into a Microsoft Excel spreadhseet.
Solutions - I'm going to offer you two:
a) To send the output as a text file - delimited by tabs between columns, and with new lines for each new line. Add appropriate ... | 2008-01-25 |
1515 | Keeping staff up to date on hotel room status Communication - communication of the immediate status of hotel rooms, of events that have happened out of the norm, of the reasons behind each of our terms and conditions, and much more is all a vital part of running our hotel - and it's not made easier by the fact that we are (and must be) run be a ... | 2008-01-22 |
1505 | Script to present commonly used images - PHP "What are the most popular pages in your picture library, and where are they used from?" An interesting question and I could analyze raw web logs to find out the answers. However, most of our images are managed by a script that retains extra information such as an image title, and uses are logged ... ... | 2008-01-14 |
1495 | Single login and single threaded models - Java and PHP On Apache Tomcat courses, I find myself explaining "single login" models and on some Java courses I explain single threaded models. In both cases, there are times that newcomers to the technologies ask "does it matter".
Answer - for a small and quiet application suite, probably not - but as the ... | 2008-01-08 |
1496 | PHP / Web 2 logging It' gone quiet here for 48 hours, hasn't it? The final run up to the first week of courses for the new year and we've been catching up with everything from cleaning blinds to updating web cam systems and ironing out final issues and catching up on other paperwork. Lots of good background and not ... | 2008-01-07 |
1379 | Simple page password protection - PHP So many demonstrations are too clever - the wood gets lost for the trees and the newcomer is left not knowing what the important bits are. So a request overnight for a REAL simple way of password protecting some content based on a single password that can be changed [in the code] from time to time provided ... | 2007-10-04 |
1355 | .php or .html extension? Morally Static Pages You'll find many pages on our web site with .php extensions, and many more with .html extensions. "So the .php files contain executable content and the .html files do not" you may think. No - not exactly; in practise almost every page actually contains some PHP / Script elements. So WHAT, WHY, HOW?
WHAT ... | 2007-09-18 |
1210 | PHP header() function - uses and new restrictions PHP's header function allows you to change the headers on your returned content so that (examples)
• The browser receives not HTML but plain text, a .jpg image or a file to save locally
example: header ('Content-type: Application/Octet-stream');
• You can change a "404" missing ... | 2007-06-07 |
1187 | Updating a page strictly every minute (PHP, Perl) For the Clock exercise that I mentioned in my last entry, I need to update the page once a minute. Exactly once a minute. At the start of the minute.
I'm using client pull, where the browser asks for the next page - so my basic request is:
<meta http-equiv="refresh" content="60; url=/clock/now.php">
but ... | 2007-05-14 |
1183 | Improving searches - from OR to AND? There's a search box on the top of all our regular pages - put a word in there, submit the form, and you'll be offered a selection of appropriate pages ... and if there's nothing relevant, you'll be offered nearby spellings. Try a search for Ireland and a search for Irelond.
Search for multiple words, ... | 2007-05-11 |
1114 | PHP Image upload script "How do I upload an image to my server?" That's a common question and I have provided many answers before ... but today I wrote a very simple script that shows just the pertinent points of uploading an image.
<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("whc").".jpg";
... | 2007-03-21 |
1009 | Passing GET parameters through Apache mod_rewrite If you're using Apache mod_rewrite to redirect a series of URLs to a single script, did you know that you can pass values entered onto a form via the GET method through as well? Simply add on %{QUERY_STRING} onto the end of your new URL. You'll need to add a ? into the target URL to ensure that the ... | 2006-12-27 |
904 | Of course I'll tell you by email It's about the time that I should be writing the next issue of "Of Course" - our twice yearly newsletter about Open Source training, and the news from Melksham and our training centre. But there's so much happening - with Well House Manor opening earlier this month, and with an initial 3 months 'running ... | 2006-10-25 |
847 | Image maps for navigation - a straightforward example Image maps can be a really simple and effective way of selecting from a series of options - a little bit more flexible that straightforward HTML links. We use an image map on every one of of main "Well House Consultants" pages - click on any on the languages named in our banner, and you'll be taken ... | 2006-08-28 |
767 | Finding the language preference of a web site visitor I can (and do) identify the country of origin of over 98% of the visitors to our web site using the maxmind database. But does that tell me what their native language is? No - it only gives me a clue.
A further clue is available from the accept-language header that's returned by browsers, and is available ... | 2006-06-19 |
542 | Morning image, afternoon image "I want to show one picture on my website in the morning and a different one in the afternoon".
Doesn't that sound like it's a simple request ... yet - as ever with computing - it raises a whole lot more questions, with a raft of possible answers.
* Do you want the time from the server? Where's ... | 2006-06-09 |
565 | Using PHP to output images, XML, Style sheets, etc PHP is usually used to generate a stream of HTML to be sent to the browser, but if you use the header function within your page you can use it to send any other type you wish. For example, if I include
header("Content-type: image/jpeg");
then I can script the production of images. Easy? Yes, but ... | 2006-06-09 |
220 | When to use Frames Frames are an HTML feature that people seem to love or hate. They do provide an extra power to how information can be navigated on a web page by allowing partial page refreshes and partial page scrolls BUT there are a number of things on the "downside" too. Gary White will tell you all about the downside ... | 2006-06-05 |
Maintaining state.
Cookie examples.
Headers, Heads and Bodies.
Uses of Cookies.
Accessibility - a practical example of cookies.
Example using PHP built-in session functions.
Why email from the server?.
Informing the system owner.
Emailing system users.
Other users.
Emailing from the server.
Configuration.
Sending a simple email.
Adding to the headers.
Sending attachments.
A practical example of mailing from PHP.
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Ruby,
Lua,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.