blob: 7f327f00b33841f1337d702f345dac81aa1a7548 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001################
2Common Functions
3################
4
5CodeIgniter uses a few functions for its operation that are globally
6defined, and are available to you at any point. These do not require
7loading any libraries or helpers.
8
9is_php('version_number')
Andrey Andreev3fb02672012-10-22 16:48:01 +030010========================
Derek Jones8ede1a22011-10-05 13:34:52 -050011
12is_php() determines of the PHP version being used is greater than the
13supplied version_number.
14
15::
16
Derek Jones46715e52011-10-05 17:36:22 -050017 if (is_php('5.3.0'))
18 {
19 $str = quoted_printable_encode($str);
20 }
Derek Jones8ede1a22011-10-05 13:34:52 -050021
22Returns boolean TRUE if the installed version of PHP is equal to or
23greater than the supplied version number. Returns FALSE if the installed
24version of PHP is lower than the supplied version number.
25
26is_really_writable('path/to/file')
Andrey Andreev3fb02672012-10-22 16:48:01 +030027==================================
Derek Jones8ede1a22011-10-05 13:34:52 -050028
29is_writable() returns TRUE on Windows servers when you really can't
30write to the file as the OS reports to PHP as FALSE only if the
31read-only attribute is marked. This function determines if a file is
32actually writable by attempting to write to it first. Generally only
33recommended on platforms where this information may be unreliable.
34
35::
36
Derek Jones46715e52011-10-05 17:36:22 -050037 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 Jones8ede1a22011-10-05 13:34:52 -050045
46config_item('item_key')
Andrey Andreev3fb02672012-10-22 16:48:01 +030047=======================
Derek Jones8ede1a22011-10-05 13:34:52 -050048
Andrey Andreev7b18a3f2012-11-04 20:27:35 +020049The :doc:`Config Library <../libraries/config>` is the preferred way of
50accessing configuration information, however ``config_item()`` can be used
51to retrieve single keys. See :doc:`Config Library <../libraries/config>`
52documentation 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 Jones8ede1a22011-10-05 13:34:52 -050057
Derek Jones46715e52011-10-05 17:36:22 -050058show_error('message'), show_404('page'), log_message('level', 'message')
59========================================================================
Derek Jones8ede1a22011-10-05 13:34:52 -050060
61These are each outlined on the :doc:`Error Handling <errors>` page.
62
Andrey Andreev3fb02672012-10-22 16:48:01 +030063set_status_header(code, 'text')
64===============================
Derek Jones8ede1a22011-10-05 13:34:52 -050065
66Permits you to manually set a server status header. Example::
67
Derek Jones46715e52011-10-05 17:36:22 -050068 set_status_header(401);
69 // Sets the header as: Unauthorized
Derek Jones8ede1a22011-10-05 13:34:52 -050070
71`See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for
72a full list of headers.
73
74remove_invisible_characters($str)
Andrey Andreev3fb02672012-10-22 16:48:01 +030075=================================
Derek Jones8ede1a22011-10-05 13:34:52 -050076
77This function prevents inserting null characters between ascii
78characters, like Java\\0script.
79
80html_escape($mixed)
Andrey Andreev3fb02672012-10-22 16:48:01 +030081===================
Derek Jones8ede1a22011-10-05 13:34:52 -050082
Andrey Andreev3fb02672012-10-22 16:48:01 +030083This function provides short cut for ``htmlspecialchars()`` function. It
Derek Jones8ede1a22011-10-05 13:34:52 -050084accepts string and array. To prevent Cross Site Scripting (XSS), it is
85very useful.
Andrey Andreev6ef498b2012-06-05 22:01:58 +030086
87get_mimes()
Andrey Andreev3fb02672012-10-22 16:48:01 +030088===========
Andrey Andreev6ef498b2012-06-05 22:01:58 +030089
Andrey Andreev3fb02672012-10-22 16:48:01 +030090This function returns the MIMEs array *from config/mimes.php*.
91
92is_https()
93==========
94
95Returns TRUE if a secure (HTTPS) connection is used and FALSE
96in any other case (including non-HTTP requests).