Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ################ |
| 2 | Common Functions |
| 3 | ################ |
| 4 | |
| 5 | CodeIgniter uses a few functions for its operation that are globally |
| 6 | defined, and are available to you at any point. These do not require |
| 7 | loading any libraries or helpers. |
| 8 | |
| 9 | is_php('version_number') |
| 10 | ========================== |
| 11 | |
| 12 | is_php() determines of the PHP version being used is greater than the |
| 13 | supplied version_number. |
| 14 | |
| 15 | :: |
| 16 | |
| 17 | if (is_php('5.3.0')) { $str = quoted_printable_encode($str); } |
| 18 | |
| 19 | Returns boolean TRUE if the installed version of PHP is equal to or |
| 20 | greater than the supplied version number. Returns FALSE if the installed |
| 21 | version of PHP is lower than the supplied version number. |
| 22 | |
| 23 | is_really_writable('path/to/file') |
| 24 | ==================================== |
| 25 | |
| 26 | is_writable() returns TRUE on Windows servers when you really can't |
| 27 | write to the file as the OS reports to PHP as FALSE only if the |
| 28 | read-only attribute is marked. This function determines if a file is |
| 29 | actually writable by attempting to write to it first. Generally only |
| 30 | recommended on platforms where this information may be unreliable. |
| 31 | |
| 32 | :: |
| 33 | |
| 34 | if (is_really_writable('file.txt')) { echo "I could write to this if I wanted to"; } else { echo "File is not writable"; } |
| 35 | |
| 36 | config_item('item_key') |
| 37 | ========================= |
| 38 | |
| 39 | The :doc:`Config library <../libraries/config>` is the preferred way of |
| 40 | accessing configuration information, however config_item() can be used |
| 41 | to retrieve single keys. See Config library documentation for more |
| 42 | information. |
| 43 | |
| 44 | show_error('message'), show_404('page'), log_message('level', |
| 45 | 'message') |
| 46 | ========== |
| 47 | |
| 48 | These are each outlined on the :doc:`Error Handling <errors>` page. |
| 49 | |
| 50 | set_status_header(code, 'text'); |
| 51 | ================================== |
| 52 | |
| 53 | Permits you to manually set a server status header. Example:: |
| 54 | |
| 55 | set_status_header(401); // Sets the header as: Unauthorized |
| 56 | |
| 57 | `See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for |
| 58 | a full list of headers. |
| 59 | |
| 60 | remove_invisible_characters($str) |
| 61 | =================================== |
| 62 | |
| 63 | This function prevents inserting null characters between ascii |
| 64 | characters, like Java\\0script. |
| 65 | |
| 66 | html_escape($mixed) |
| 67 | ==================== |
| 68 | |
| 69 | This function provides short cut for htmlspecialchars() function. It |
| 70 | accepts string and array. To prevent Cross Site Scripting (XSS), it is |
| 71 | very useful. |