Home
Username:
Password:
FileMaker 9 & PHP Foundations Tutorials

PHP Basics / Redirects & Resources

Subtitles of the Movie

In this lesson, we're going to learn how to redirect the browser to a different page. And then I'm going to give you additional resources where you can learn more about PHP programming as you go through these lessons. To redirect the browser to a different page, you call the header function in PHP. There are many times in PHP where you'll have pages that just do PHP processing, such as interacting with your FileMaker database or authorizing a credit card transaction. In this example, 0207 underscore checkout dot PHP, we'll say that this page is authorizing or going through some sort of checkout system. When it's complete, we want to redirect the browser to the 0207 receipt page. To redirect the browser, you use the PHP header function. The header function allows you to send raw HTTP headers to the browser. In this case, which is a special case scenario, we're going to pass the attribute location colon. That's a special attribute, which will redirect the browser to the page that you specify after the colon. You must specify a relative or an absolute path to the page you want to go to. If you want to send them to a different site, specify the full URL to that site. In this case, we're going to send them to the 0207 underscore receipt.php page. Now after we've called the header function, we want to make sure that no more PHP code gets processed. Just because we've called the header function, it doesn't mean that PHP will stop processing the code. But there's no doubt that if you redirected the user to a different page, you don't want to keep executing code. So to play it safe and make sure you don't get unexpected results, always type in the exit command, which tells PHP to stop processing any more code. One more thing to note about using the header function. And this is very important. You want to make sure that no output has been sent to the browser before you call the header function. That means any white space or any output from an output function such as echo or print or another. Once you send output to the browser, if you try to call the header function, an error will result and your application will break. Never send any output to the browser, including any white space before your PHP declaration before calling the header function. If part of your PHP logic does use output functions such as echo or print, make sure to use output buffering as taught in the previous lesson. Let's go ahead and call this page in our browser and see the results. Here's our checkout page. When we load it, we're going to get redirected to the receipt page. Here's the 0207 receipt page. That's how you redirect the browser in PHP. I'm going to go ahead now and show you additional resources so you can learn more about PHP while you're learning through these tutorials. First and foremost is the PHP.net website which contains all the information about PHP. Here you can download the most recently released version of PHP and search through their online manuals and documentation. For instance, let's say I wanted to learn more about working with files in PHP. If I type in the word file and hit return, PHP immediately takes me to the file function. If I scroll down, I learn examples about how the file function works. At the bottom of the description or the manual for the file function, I can get related functions that work with files. The PHP manual does a really good job of always giving you links at related functions. The last think to note about the online PHP manual is the user-contributed notes. These have proven invaluable time and time again when trying to get over a problem in your PHP programming. Many PHP programmers have learned through trial and error and many hours of hard work how to use PHP in a specific way. In these user contributed notes, you'll learn invaluable lessons that will save you hours of work and help you to learn PHP faster. Another great website is the PHP tutorial site at w3schools.com. Here they have an excellent tutorial and online documentation about using PHP. W3schools has great tutorials on all different kinds of web codes, including HTML, XHTML, CSS and so on. W3schools is an excellent resource for any type of web development. Then there's the WebMonkey website, which is largely driven by the developer community. Here you can read about specific tutorials on how to accomplish certain tasks using PHP. Say, for instance, you want to send an HTTP e-mail with PHP. There are tutorials here how explain how to do that. And even sample objects and functions that you can download and use. If you're using Windows Vista, you have the ability to download gadgets and use them in your Windows sidebar. There's a PHP function gadget, which you can download from GoZipLine.com. If you're using Mac OS 10, there are PHP widgets you can download for your dashboard. Here are a couple dashboard widgets that help me with my PHP programming, including the PHP cheat sheet, which helps me with my formatting functions, regular expressions and then the actual PHP documentation in a dashboard widget. Here I can type in a function such as the header function. And here I get a list of all the different functions that match the word header. If I click on the one I want, I get all the documentation from the online PHP manual. The only thing missing here is the user-contributed notes. So it's well worth my while to still visit the PHP.net site. This concludes our lesson in showing you how to redirect in PHP and where you can get additional information on learning PHP throughout these lessons.

Tutorial Information

Course: FileMaker 9 & PHP Foundations
Author: Lance Hallberg
SKU: 33786
ISBN: 1-933736-99-2
Release Date: 2007-08-22
Duration: 9.5 hrs / 107 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available