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') |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 10 | ======================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 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') |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 27 | ================================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 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') |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 47 | ======================= |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 48 | |
Andrey Andreev | 7b18a3f | 2012-11-04 20:27:35 +0200 | [diff] [blame^] | 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 :doc:`Config Library <../libraries/config>` |
| 52 | documentation for more information. |
| 53 | |
| 54 | .. important:: This function only returns values set in your configuration |
| 55 | files. It does not take into account config values that are |
| 56 | dynamically set at runtime. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 57 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 58 | show_error('message'), show_404('page'), log_message('level', 'message') |
| 59 | ======================================================================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 60 | |
| 61 | These are each outlined on the :doc:`Error Handling <errors>` page. |
| 62 | |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 63 | set_status_header(code, 'text') |
| 64 | =============================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 65 | |
| 66 | Permits you to manually set a server status header. Example:: |
| 67 | |
Derek Jones | 46715e5 | 2011-10-05 17:36:22 -0500 | [diff] [blame] | 68 | set_status_header(401); |
| 69 | // Sets the header as: Unauthorized |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 70 | |
| 71 | `See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for |
| 72 | a full list of headers. |
| 73 | |
| 74 | remove_invisible_characters($str) |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 75 | ================================= |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 76 | |
| 77 | This function prevents inserting null characters between ascii |
| 78 | characters, like Java\\0script. |
| 79 | |
| 80 | html_escape($mixed) |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 81 | =================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 82 | |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 83 | This function provides short cut for ``htmlspecialchars()`` function. It |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 84 | accepts string and array. To prevent Cross Site Scripting (XSS), it is |
| 85 | very useful. |
Andrey Andreev | 6ef498b | 2012-06-05 22:01:58 +0300 | [diff] [blame] | 86 | |
| 87 | get_mimes() |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 88 | =========== |
Andrey Andreev | 6ef498b | 2012-06-05 22:01:58 +0300 | [diff] [blame] | 89 | |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 90 | This function returns the MIMEs array *from config/mimes.php*. |
| 91 | |
| 92 | is_https() |
| 93 | ========== |
| 94 | |
| 95 | Returns TRUE if a secure (HTTPS) connection is used and FALSE |
| 96 | in any other case (including non-HTTP requests). |