Files are a great place to store information across requests, and PHP gives you lots of ways to manipulate them. Older PHP scripts are unlikely to contain easier functions such as file_get_contents() and file_put_contents(), but these are very efficient functions and you should make use of them yourself.
Despite their flexibility, there is only so far files can take you - no matter how short the space between your fopen() s and fclose() s, it is still possible that two scripts may try to read from the same file at the same time.
File permissions can often be confusing, particularly on a server that does not belong to you. In this circumstance, make use of functions like is_readable() to make sure you have the right permissions before attempting any operations.
Thanks to the flexibility of PHP, you can treat HTTP and FTP connections as if they were local files, reading and writing freely.
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Exercises >>
Previous chapter: Parsing a configuration file
Jump to:
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.