blob: 70563b8d2125de5c1b3e28b27b028712c9bb3834 [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')
10==========================
11
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')
27====================================
28
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')
47=========================
48
49The :doc:`Config library <../libraries/config>` is the preferred way of
50accessing configuration information, however config_item() can be used
51to retrieve single keys. See Config library documentation for more
52information.
53
Derek Jones46715e52011-10-05 17:36:22 -050054show_error('message'), show_404('page'), log_message('level', 'message')
55========================================================================
Derek Jones8ede1a22011-10-05 13:34:52 -050056
57These are each outlined on the :doc:`Error Handling <errors>` page.
58
59set_status_header(code, 'text');
Derek Jones46715e52011-10-05 17:36:22 -050060================================
Derek Jones8ede1a22011-10-05 13:34:52 -050061
62Permits you to manually set a server status header. Example::
63
Derek Jones46715e52011-10-05 17:36:22 -050064 set_status_header(401);
65 // Sets the header as: Unauthorized
Derek Jones8ede1a22011-10-05 13:34:52 -050066
67`See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for
68a full list of headers.
69
70remove_invisible_characters($str)
71===================================
72
73This function prevents inserting null characters between ascii
74characters, like Java\\0script.
75
76html_escape($mixed)
77====================
78
79This function provides short cut for htmlspecialchars() function. It
80accepts string and array. To prevent Cross Site Scripting (XSS), it is
81very useful.