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 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 17 | if (is_php('5.3.0')) |
| 18 | { |
| 19 | $str = quoted_printable_encode($str); |
| 20 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 21 | |
| 22 | Returns boolean TRUE if the installed version of PHP is equal to or |
| 23 | greater than the supplied version number. Returns FALSE if the installed |
| 24 | version of PHP is lower than the supplied version number. |
| 25 | |
| 26 | is_really_writable('path/to/file') |
| 27 | ==================================== |
| 28 | |
| 29 | is_writable() returns TRUE on Windows servers when you really can't |
| 30 | write to the file as the OS reports to PHP as FALSE only if the |
| 31 | read-only attribute is marked. This function determines if a file is |
| 32 | actually writable by attempting to write to it first. Generally only |
| 33 | recommended on platforms where this information may be unreliable. |
| 34 | |
| 35 | :: |
| 36 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 37 | if (is_really_writable('file.txt')) |
| 38 | { |
| 39 | echo "I could write to this if I wanted to"; |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | echo "File is not writable"; |
| 44 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | |
| 46 | config_item('item_key') |
| 47 | ========================= |
| 48 | |
| 49 | The :doc:`Config library <../libraries/config>` is the preferred way of |
| 50 | accessing configuration information, however config_item() can be used |
| 51 | to retrieve single keys. See Config library documentation for more |
| 52 | information. |
| 53 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 54 | show_error('message'), show_404('page'), log_message('level', 'message') |
| 55 | ======================================================================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | |
| 57 | These are each outlined on the :doc:`Error Handling <errors>` page. |
| 58 | |
| 59 | set_status_header(code, 'text'); |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 60 | ================================ |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 61 | |
| 62 | Permits you to manually set a server status header. Example:: |
| 63 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 64 | set_status_header(401); |
| 65 | // Sets the header as: Unauthorized |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 66 | |
| 67 | `See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for |
| 68 | a full list of headers. |
| 69 | |
| 70 | remove_invisible_characters($str) |
| 71 | =================================== |
| 72 | |
| 73 | This function prevents inserting null characters between ascii |
| 74 | characters, like Java\\0script. |
| 75 | |
| 76 | html_escape($mixed) |
| 77 | ==================== |
| 78 | |
| 79 | This function provides short cut for htmlspecialchars() function. It |
| 80 | accepts string and array. To prevent Cross Site Scripting (XSS), it is |
| 81 | very useful. |
Andrey Andreev | 6ef498b | 2012-06-05 22:01:58 +0300 | [diff] [blame] | 82 | |
| 83 | get_mimes() |
| 84 | ============= |
| 85 | |
| 86 | This function returns the MIMEs array from config/mimes.php. |