- PHP stands for PHP: Hypertext Preprocessor
- PHP is a widely-used, open source scripting language
- PHP scripts are executed on the server
- PHP is free to download and use
- PHP files can contain text, HTML, JavaScript code, and PHP code
- PHP code are executed on the server, and the result is returned to the browser as plain HTML
- PHP files have a default file extension of “.php”
- PHP can generate dynamic page content
- PHP can create, open, read, write, and close files on the server
- PHP can collect form data
- PHP can send and receive cookies
- PHP can add, delete, modify data in your database
- PHP can restrict users to access some pages on your website
- PHP can encrypt data
- PHP runs on different platforms (Windows, Linux, Unix, Mac OS X, etc.)
- PHP is compatible with almost all servers used today (Apache, IIS, etc.)
- PHP has support for a wide range of databases
- PHP is free. Download it from the official PHP resource: www.php.net
- PHP is easy to learn and runs efficiently on the server side
Using PHP:
This section gathers many common errors that you may face while writing PHP scripts:
- I cannot remember the parameter order of PHP functions, are they random?
- I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?
- I need to convert all single-quotes (‘) to a backslash followed by a single-quote (\’). How can I do this with a regular expression? I’d also like to convert ” to \” and \ to \\.
- All my ” turn into \” and my ‘ turn into \’, how do I get rid of all these unwanted backslashes? How and why did they get there?
- How does the PHP directive register_globals affect me?
- When I do the following, the output is printed in the wrong order: what’s going on?
- Hey, what happened to my newlines?
- I get the message ‘Warning: Cannot send session cookie – headers already sent…’ or ‘Cannot add header information – headers already sent…’.
- I need to access information in the request header directly. How can I do this?
- When I try to use authentication with IIS I get ‘No Input file specified’.
- Windows: I can’t access files shared on another computer using IIS
- How am I supposed to mix XML and PHP? It complains about my
- :
- Superglobal arrays such as
- ,
- , and
- , etc. are available as of PHP 4.1.0. For more information, read the manual section on
- Assuming this is for a database, use the escaping mechanism that comes with the database. For example, use
- with MySQL and
- with PostgreSQL. There is also the generic
- and
- functions, that are more common with older PHP code.
Note
- :
- The
- directive defaults to
- . It essentially runs
- on all GET, POST, and COOKIE data.
- may be used to remove them.
All my ” turn into \” and my ‘ turn into \’, how do I get rid of all these unwanted backslashes? How and why did they get there?
- Most likely the backslashes magically exist because the PHP directive
- is on. This is an old feature of PHP, and should be disabled and not relied upon. Also, the PHP function
- may be used to strip the backslashes from the
- .
- :
- The
- directive defaults to
- . It essentially runs
- on all GET, POST, and COOKIE data.
- may be used to remove them.
How does the PHP directive register_globals affect me?
Warning
- This feature has been
- as of PHP 5.3.0 and
- as of PHP 5.4.0.
- First, an explanation about what this ini setting does. Let’s say the following URL is used:
- and in
- we might have the following PHP code:
- The code above demonstrates how register_globals creates a lot of variables. For years this type of coding has been frowned upon, and for years it’s been disabled by default. So although most web hosts disable register_globals, there are still outdated articles, tutorials, and books that require it to be on. Plan accordingly.
- :
- The
- directive
- The
Handling external variables
- Use
- instead
- In the example above, we used an
- that contained a QUERY_STRING. Passing information like this is done through a GET HTTP Request, so this is why the superglobal
- was used.
When I do the following, the output is printed in the wrong order:
W
- To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to
- the value, not
- it.
Hey, what happened to my newlines?
I get the message ‘Warning: Cannot send session cookie – headers already sent…’ or ‘Cannot add header information – headers already sent…’.
- The functions
- ,
- , and the
- need to add headers to the output stream but headers can only be sent before all other content. There can be no output before using these functions, output such as HTML. The function
- will check if your script has already sent headers and see also the
- .
I need to access information in the request header directly. How can I do this?
- The
- function will do this if you are running PHP as an Apache module. So, the following bit of code will show you all the request headers:
- \n";
- }
- ?>
- See also
- ,
- , and
- The security model of IIS is at fault here. This is a problem common to all CGI programs running under IIS. A workaround is to create a plain HTML file (not parsed by PHP) as the entry page into an authenticated directory. Then use a META tag to redirect to the PHP page, or have a link to the PHP page. PHP will then recognize the authentication correctly. With the ISAPI module, this is not a problem. This should not effect other NT web servers. For more information, see:
- and the manual section on
- .
- You have to change the
- . Locate your PHP file and go to its properties. Go to the
- tab,
- .You can fix the problem either by unticking
- and leaving
- ticked, or, by ticking
- and editing the user as he may not have the access right.
- . The default for this directive is
- .
- Read the manual page on
- as it includes a partial list of predefined variables available to your script. A complete list of available variables (and much more information) can be seen by calling the
- function. Be sure to read the manual section on
- as it describes common scenarios for external variables, like from a HTML form, a Cookie, and the URL.
Note
- :
- As of PHP 4.2.0, the default value for the PHP directive
- is
- . The PHP community discourages developers from relying on this directive, and encourages the use of other means, such as the
- .
How can I generate PDF files without using the non-free and commercial libraries like PDFLib? I’d like something that’s free and doesn’t require external PDF libraries.
<