Databases Reference
In-Depth Information
Web server
form.html
process.php
Inserts a new artist entry
into the database
receipt.php
2. Server sends
form.html
4. Server sends
Location: receipt.php
header
6. Server sends
receipt.php
output
1. Browser requests
form.html
3. Browser submits form
data and requests
process.php
5. Browser requests
receipt.php
HTML content (form)
HTML content
(confirmation)
process.php not executed each time
the confirmation page is loaded,
only when receipt.php is executed
User system (browser)
Figure 14-4. A solution to the reload problem
Before we end this section, we should point out that the header( ) function is associated
with the very common error in which the PHP engine complains that it cannot send
any header information:
Warning: Cannot modify header information
- headers already sent by (output started at logout.php:2)
This error occurs because the web server sends headers as soon as any output is sent
to the browser. If you generate any output, or even accidentally leave a blank line or
even a single space character before the PHP start tag, the server treats this output as
content, and sends it to the browser along with the HTTP headers. You must ensure
you don't generate any output before the call to the header( ) function. The
session_start( ) function sends its own headers to the browser, and so you'll run into
the same problem if you have any output before a call to this function.
Using PHP for Command-Line Scripts
PHP scripts don't need to be run from a web server—although that's how the majority
of PHP scripts are deployed. In this section, we'll briefly look at how you can run PHP
scripts from the command line. This allows you to query the MySQL server from the
command line to generate reports and to import or export data.
Consider Example 14-5, which simply says “Hello, world!”.
 
Search WWH ::




Custom Search