PageRenderTime 93ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/manual/phpfi2.php

https://github.com/Robervaldo/web-php
PHP | 7638 lines | 6754 code | 854 blank | 30 comment | 300 complexity | d678613bf0df6aa12b2164d01c894d48 MD5 | raw file
  1. <?php
  2. // $Id$
  3. $_SERVER['BASE_PAGE'] = 'manual/phpfi2.php';
  4. include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
  5. site_header('PHP/FI Version 2.0 Documentation');
  6. ?>
  7. <!--
  8. Documentation is like sex: when it is good, it is very, very good; and
  9. when it is bad, it is better than nothing.
  10. ++ Dick Brandon
  11. -->
  12. <h1 style="text-align: center;">PHP/FI Version 2.0</h1>
  13. <h1>Table of Contents</h1>
  14. <ol>
  15. <li><a href="#history">Brief History</a></li>
  16. <li><a href="#install">Installation Instructions</a></li>
  17. <li><a href="#starting">So, what can I do with PHP/FI?</a></li>
  18. <li><a href="#redirect">CGI Redirection</a></li>
  19. <li><a href="#security">Security Issues</a></li>
  20. <li><a href="#safemode">Safe Mode</a></li>
  21. <li><a href="#commandline">Running PHP/FI from the Command
  22. Line</a></li>
  23. <li><a href="#http_auth">HTTP Authentication</a></li>
  24. <li><a href="#requestvars">Apache Request Variables</a></li>
  25. <li><a href="#module">Apache Module Notes</a></li>
  26. <li><a href="#directives">Apache Module Configuration
  27. Directives</a></li>
  28. <li><a href="#fastcgi">FastCGI Support</a></li>
  29. <li><a href="#access">Access Control</a></li>
  30. <li><a href="#logging">Access Logging</a></li>
  31. <li><a href="#relative">Relative vs. Absolute URL's - or, Why
  32. do my Images Break?</a></li>
  33. <li>
  34. <a href="#getpost">How PHP/FI handles GET and POST method
  35. data</a>
  36. <ul>
  37. <li><a href="#selmul"><tt>SELECT MULTIPLE</tt> and
  38. PHP</a></li>
  39. <li><a href="#imagecoord"><tt>IMAGE SUBMIT</tt> and
  40. PHP</a></li>
  41. </ul>
  42. </li>
  43. <li><a href="#gd_support">GD (a graphics library for GIF
  44. creation) Support in PHP</a></li>
  45. <li><a href="#virtual_hosts">PHP/FI and Virtual Hosts</a></li>
  46. <li><a href="#upload">File Upload Support</a></li>
  47. <li><a href="#cookies">Cookie Support</a></li>
  48. <li><a href="#msql_support">mSQL Support</a></li>
  49. <li><a href="#pg95_support">Postgres95/PostgreSQL
  50. Support</a></li>
  51. <li><a href="#mysql_support">mysql Support</a></li>
  52. <li><a href="#solid_support">Solid Support</a></li>
  53. <li><a href="#sybase_support">Sybase Support</a></li>
  54. <li><a href="#oracle_support">Oracle Support</a></li>
  55. <li><a href="#illustra_support">Illustra Support</a></li>
  56. <li><a href="#adabas_support">Adabas Support</a></li>
  57. <li><a href="#regexp">Regular Expressions</a></li>
  58. <li><a href="#escapes">Escape Characters</a></li>
  59. <li><a href="#octal">Octal notation of Unix file
  60. permissions</a></li>
  61. <li>
  62. <a href="#script">PHP/FI Script Language</a>
  63. <ul>
  64. <li><a href="#syntax">Syntax</a></li>
  65. <li><a href="#vars">Variables</a></li>
  66. <li><a href="#assoc">Associative Arrays</a></li>
  67. <li><a href="#varvars">Variable Variables</a></li>
  68. <li><a href="#lang">Language Constructs</a></li>
  69. <li><a href="#user_funcs">User-Defined Functions</a></li>
  70. <li><a href="#scope">Scope of Variables</a></li>
  71. <li><a href="#math">Mathematical Expressions</a></li>
  72. <li><a href="#while">While Loops</a></li>
  73. <li><a href="#switch">Switch Construct</a></li>
  74. <li><a href="#secure">Secure Variables - Defeating GET
  75. method hacks</a></li>
  76. <li><a href="#overload">Overloaded Operators and dealing
  77. with variable types</a></li>
  78. <li><a href="#quiet">Suppressing Errors from function
  79. calls</a></li>
  80. <li><a href="#funcs">Internal Functions</a></li>
  81. </ul>
  82. </li>
  83. <li><a href="#addfunc">Adding your own functions to
  84. PHP/FI</a></li>
  85. <li><a href="#hacknotes">Notes for Code Hacks</a></li>
  86. </ol>
  87. <hr />
  88. <h2><a name="history" id="history">Brief History</a></h2>
  89. <p>PHP began life as a simple little cgi wrapper written in Perl.
  90. I wrote it in an afternoon during a period between contracts when
  91. I needed a quick tool to get an idea of who was reading my online
  92. resume. It was never intended to go beyond my own private use.
  93. The web server where I had my resume was extremely overloaded and
  94. had constant problems forking processes. I rewrote the Perl
  95. wrapper in C to get rid of the considerable overhead of having to
  96. fork Perl each time my resume was accessed.</p>
  97. <p>Eventually other people on the same web server came across my
  98. wrapper and asked if they could use it. Then, as inevitably
  99. happens, they started asking for more features. I added more
  100. features and finally put together a semi-complete distribution
  101. along with documentation, a mailing-list and a FAQ. The name of
  102. this first package was Personal Home Page Tools, which later
  103. became Personal Home Page Construction Kit.</p>
  104. <p>At the same time I started playing with databases and wrote a
  105. tool to easily embed SQL queries into web pages. It was basically
  106. another CGI wrapper that parsed SQL queries and made it easy to
  107. create forms and tables based on these queries. This tool was
  108. named FI (Form Interpreter).</p>
  109. <p>PHP/FI version 2.0 is a complete rewrite of these two packages
  110. combined into a single program. It has now evolved to the point
  111. where it is a simple programming language embedded inside HTML
  112. files. The original acronym, PHP, has stuck. It isn't really
  113. appropriate any longer. PHP/FI is used more for entire web sites
  114. today than for small Personal Home Page setups. By whatever name,
  115. it eliminates the need for numerous small Perl cgi programs by
  116. allowing you to place simple scripts directly in your HTML files.
  117. This speeds up the overall performance of your web pages since
  118. the overhead of forking Perl several times has been eliminated.
  119. It also makes it easier to manage large web sites by placing all
  120. components of a web page in a single html file. By including
  121. support for various databases, it also makes it trivial to
  122. develop database enabled web pages. Many people find the embedded
  123. nature much easier to deal with than trying to create separate
  124. HTML and CGI files.</p>
  125. <p>PHP Version 3.0 is yet another rewrite. If you are just
  126. starting out with PHP, I suggest that you start with Version 3.0
  127. instead of continuing with 2.0 at this point. PHP3 is quickly
  128. going to replace PHP/FI 2.0 and all development efforts are now
  129. focused on PHP3. Any remaining bugs in PHP/FI 2.0 are unlikely to
  130. be fixed unless they are straightforward. More information on
  131. PHP3 can be found at <a href=
  132. "http://www.lerdorf.on.ca/php3/">http://www.lerdorf.on.ca/php3</a>.</p>
  133. <p>Throughout this documentation any references to PHP, FI or
  134. PHP/FI all refer to the same thing. The difference between PHP
  135. and FI is only a conceptual one. Both are built from the same
  136. source distribution. When I build the package without any access
  137. logging or access restriction support, I call my binary FI. When
  138. I build with these options, I call it PHP.</p>
  139. <hr />
  140. <h2><a name="install" id="install">Installation
  141. Instructions</a></h2>
  142. <dl>
  143. <dt><big>Before You Begin</big></dt>
  144. <dd>
  145. <p>If you have absolutely no Unix experience, you may want to
  146. ask around for someone with a little bit of Unix knowledge to
  147. help you through this installation. Every attempt has been
  148. made to make it as simple as possible, but since the software
  149. is quite involved and relies on a number of different
  150. components, it is not realistic to assume it will go smoothly
  151. on all systems. You will probably need someone around who
  152. knows the particulars of the destination system well.</p>
  153. </dd>
  154. <dt><big>Things You Need To Know Before
  155. Installing</big></dt>
  156. <dd>
  157. <p>- Can you run both get and post method cgi programs on
  158. your server?<br />
  159. <em>This is not relevant if you installing the Apache module
  160. version.</em> If not, you can not use this package. On many
  161. public ISP's CGI programs are either disallowed or severely
  162. restricted. If this is the case on your system, talk to your
  163. system administrator and ask him/her to have a look at this
  164. package and see if they will install it for you.</p>
  165. </dd>
  166. <dd>
  167. <p>- If you have mSQL installed on your system, you need to
  168. know the base directory of this installation.</p>
  169. </dd>
  170. <dd>
  171. <p>- If you have Postgres95 or PostgreSQL installed on your
  172. system, you need to know the base directory of this
  173. installation.</p>
  174. </dd>
  175. <dd>
  176. <p>- If you are going to be storing log and access
  177. configuration files in an NFS-mounted directory and your
  178. system does not provide NFS file locking then you will need
  179. to define the NFS_HACK variable manually in the src/Makefile
  180. and you may want to use a slightly modified version of the
  181. gdbm library. See the <strong>nfs_hack.txt</strong> file in
  182. the doc directory for more information on this.</p>
  183. </dd>
  184. <dd>
  185. <p>- Note that if you are not interested in using PHP to
  186. track accesses to your pages, do not compile this option into
  187. the binary. You should also leave out the access restriction
  188. code. There is considerable overhead in including these
  189. options.</p>
  190. </dd>
  191. <dd>
  192. <p>- If you are installing the Apache module version, you
  193. will need to know the Apache src code directory location.</p>
  194. </dd>
  195. <dt><big>Installation Steps</big></dt>
  196. <dd>
  197. <p><em><strong>Step 1.</strong></em></p>
  198. <p>Run the install program: <tt>./install</tt></p>
  199. <p>You will be asked a number of questions. If you do not
  200. understand what is being asked, simply hit return. The
  201. default choice should be safe on most systems. This doesn't
  202. apply for the questions asking you to specify a directory for
  203. your configuration and log files however. Choose any
  204. directory to which the httpd (usually "nobody") has write
  205. privileges. You may create this directory manually somewhere
  206. and simply <strong><tt>chown nobody
  207. directory</tt></strong>.</p>
  208. <p><em><strong>Step 2.</strong></em></p>
  209. <p>Go into the src directory: <tt>cd src</tt></p>
  210. <p>Have a look at the php.h file. There are a number of
  211. compile-time options that can be set here.</p>
  212. <p><em><strong>Step 3.</strong></em></p>
  213. <p>type: <tt>make</tt></p>
  214. <p>This will create the actual executable program file named
  215. <em>php.cgi</em> by default, or if you are installing the
  216. Apache module, it will create a <em>libphp.a</em> file.</p>
  217. <p><em><strong>Step 4. (if you are not installing the Apache
  218. module version)</strong></em></p>
  219. <p>Copy the <strong>php.cgi</strong> binary to your system's
  220. cgi-bin directory. If you do not have access to do this and
  221. wish to install it in your own personal directory, you may do
  222. so, but you should set the setuid bit on the executable with:
  223. <tt>chmod u+s /path/php.cgi</tt></p>
  224. <p>If you do not make set the setuid bit on the binary then
  225. any files created by the binary will be owned by the user id
  226. under which the web server runs. If this is acceptable, then
  227. you can safely leave the setuid bit off.</p>
  228. <p><em><strong>Step 4. (if you are installing the Apache
  229. module version)</strong></em><br />
  230. Change to your Apache src directory where the
  231. <em>mod_php.c</em> and <em>mod_php.h</em> files should have
  232. been copied to. If they weren't which usually happens because
  233. of permission problems, copy these two files there manually.
  234. Edit your Apache Configuration file and add the EXTRA_LIBS
  235. line which was produced at the end of <strong>Step
  236. 3</strong>. And add:</p>
  237. <p><tt><strong>Module php_module mod_php.o</strong></tt></p>
  238. <p>to the very end of the file. Then type:
  239. <strong>./Configure</strong> and then <strong>make</strong>
  240. to rebuild your Apache httpd binary. Install this binary.</p>
  241. <p>Next you need to edit your Apache conf/srm.conf file and
  242. add a line like:</p>
  243. <p><tt><strong>AddType application/x-httpd-php
  244. .phtml</strong></tt></p>
  245. <p>This defines a new MIME, application/x-httpd-php, which
  246. will trigger the PHP module to parse any file ending with the
  247. <em>.phtml</em> extension. You can pick any extension you
  248. like for this.</p>
  249. <p>You may not want to enable everyone to run PHP parsed
  250. files. You can place the above AddType line within
  251. &lt;Location /path&gt;....&lt;/Location&gt; directives in the
  252. <em>access.conf</em> file to only allow PHP-parsed documents
  253. in certain directories on your server.</p>
  254. <p>Now you are ready to restart your httpd server. See the
  255. <a href="#module">Apache Module Notes</a> for more details on
  256. configuring the PHP Module.</p>
  257. </dd>
  258. <dt><big>Testing the software</big></dt>
  259. <dd>
  260. <p>Once installed you can test to see if your executable
  261. works by entering a URL similar to the following in your
  262. browser:</p>
  263. <p><tt>http://your.site.domain/cgi-bin/php.cgi</tt></p>
  264. <p>This should show you a page which contains the version
  265. number along with various other useful information.</p>
  266. <p>To test the Apache module version, create any file with a
  267. .phtml extension and put a tag like: &lt;?phpinfo()&gt; in
  268. the file and see if it gets parsed.</p>
  269. </dd>
  270. <dt><big>Using the software</big></dt>
  271. <dd>
  272. <p>To actually use the software on an existing HTML file, you
  273. can simply append the path to your file to the above URL.
  274. ie.</p>
  275. <p>
  276. <tt>http://your.site.domain/cgi-bin/php.cgi/path/file.html</tt></p>
  277. <p>You should have a look at the <a href="#redirect">CGI
  278. Redirection</a> section of this documentation. Running PHP/FI
  279. through a redirect means you can automatically have a URL
  280. like <em>http://your.site.domain/file.phtml</em> be parsed by
  281. PHP/FI.</p>
  282. <p>This does not apply to Apace module users.</p>
  283. </dd>
  284. </dl>
  285. <hr />
  286. <h2><a name="starting" id="starting">So, what can I do with
  287. PHP/FI?</a></h2>
  288. <p>The first thing you will notice if you run a page through
  289. PHP/FI is that it adds a footer with information about the number
  290. of times your page has been accessed (if you have compiled access
  291. logging into the binary). This is just a very small part of what
  292. PHP/FI can do for you. It serves another very important role as a
  293. form interpreter cgi, hence the FI part of the name. For example,
  294. if you create a form on one of your web pages, you need something
  295. to process the information on that form. Even if you just want to
  296. pass the information to another web page, you will have to have a
  297. cgi program do this for you. PHP/FI makes it extremely easy to
  298. take form data and do things with it.</p>
  299. <p><em><strong>A simple example</strong></em></p>
  300. <p>Suppose you have a form:</p>
  301. <p><tt>&lt;FORM ACTION="/cgi-bin/php.cgi/~userid/display.html"
  302. METHOD=POST&gt;<br />
  303. &lt;INPUT TYPE="text" name="name"&gt;<br />
  304. &lt;INPUT TYPE="text" name="age"&gt;<br />
  305. &lt;INPUT TYPE="submit"&gt;<br />
  306. &lt;/FORM&gt;</tt></p>
  307. <p>Your display.html file could then contain something like:</p>
  308. <p><tt>&lt;?echo "Hi $name, you are $age years
  309. old!&lt;p&gt;"&gt;</tt></p>
  310. <p>It's that simple! PHP/FI automatically creates a variable for
  311. each form input field in your form. You can then use these
  312. variables in the ACTION URL file.</p>
  313. <p>The next step once you have figured out how to use variables
  314. is to start playing with some logical flow tags in your pages.
  315. For example, if you wanted to display different messages based on
  316. something the user inputs, you would use if/else logic. In our
  317. above example, we can display different things based on the age
  318. the user entered by changing our display.html to:</p>
  319. <pre>
  320. &lt;?
  321. if($age&gt;50);
  322. echo "Hi $name, you are ancient!&lt;p&gt;";
  323. elseif($age&gt;30);
  324. echo "Hi $name, you are very old!&lt;p&gt;";
  325. else;
  326. echo "Hi $name.";
  327. endif;
  328. &gt;
  329. </pre>
  330. <p>PHP/FI provides a very powerful scripting language which will
  331. do much more than what the above simple example demonstrates. See
  332. the section on the <a href="#script">PHP/FI Script Language</a>
  333. for more information.</p>
  334. <p>You can also use PHP/FI to configure who is allowed to access
  335. your pages. This is done using a built-in configuration screen.
  336. With this you could for example specify that only people from
  337. certain domains would be allowed to see your pages, or you could
  338. create a rule which would password protect certain pages. See the
  339. <a href="#access">Access Control</a> section for more
  340. details.</p>
  341. <p>PHP/FI is also capable of receiving file uploads from any
  342. RFC-1867 compliant web browser. This feature lets people upload
  343. both text and binary files. With PHP/FI's access control and
  344. logical functions, you have full control over who is allowed to
  345. upload and what is to be done with the file once it has been
  346. uploaded. See the <a href="#upload">File Upload</a> section for
  347. more details.</p>
  348. <p>PHP/FI has support for a database package called mSQL. This
  349. allows you to put information into a database and access this
  350. information through simple embedded SQL queries right in your
  351. .HTML files. Adding a database back-end to a web page has never
  352. been easier. See the section on <a href="#msql_support">mSQL
  353. Support</a> for more information.</p>
  354. <p>PHP/FI has support for the Postgres95/PostgreSQL database
  355. package. It supports embedded SQL queries in your .HTML files.
  356. See the section on <a href="#pg95_support">Postgres95/PostgreSQL
  357. Support</a> for more information.</p>
  358. <p>PHP/FI also has support for the mysql database package. It
  359. supports embedded SQL queries in your .HTML files. See the
  360. section on <a href="#mysql_support">mysql Support</a> for more
  361. information.</p>
  362. <hr />
  363. <h2><a name="redirect" id="redirect">CGI Redirection</a></h2>
  364. <dl>
  365. <dt><strong>Apache 1.0.x Notes</strong></dt>
  366. <dd>
  367. <p>A good way to run PHP/FI is by using a cgi redirection
  368. module with the Apache server. Please note that you do not
  369. need to worry about redirection modules if you are using the
  370. Apache module version of PHP/FI. There are two of these
  371. redirection modules available. One is developed by Dave
  372. Andersen &lt;angio@aros.net&gt; and it is available at
  373. <a href=
  374. "ftp://ftp.aros.net/pub/util/apache/mod_cgi_redirect.c">ftp://ftp.aros.net/pub/util/apache/mod_cgi_redirect.c</a>
  375. and the other comes bundled with Apache and is called
  376. mod_actions.c. The modules are extremely similar. They differ
  377. slightly in their usage. Both have been tested and both work
  378. with PHP/FI.</p>
  379. <p>One large caveat at the time of this writing (Apr.20/96)
  380. is that the current official Apache release (1.0.5) has a
  381. severe limitation which prevents cgi redirected requests from
  382. having any post-method data associated with them. I have
  383. tracked this down and fixed it in my version of Apache, and
  384. there is an official patch available in the <a href=
  385. "http://php.iquest.net/files/">File Archives</a> on the
  386. <a href="http://php.iquest.net/">PHP Home Page</a>.</p>
  387. <p>A second rather large caveat with Apache 1.0.x is that it
  388. does not align double types correctly on most architectures.
  389. You may find yourself getting strange bus errors from your
  390. httpd when using mod_php, either upgrade to Apache 1.1 or
  391. edit the <i>alloc.c</i> Apache source file. In this file you
  392. will find the following piece of code:</p>
  393. <pre>
  394. union align
  395. {
  396. /* Types which are likely to have the longest RELEVANT alignment
  397. * restrictions... we don't do much with doubles.
  398. */
  399. char *cp;
  400. void (*f)();
  401. long l;
  402. FILE *fp;
  403. };
  404. </pre>
  405. <p>You will need to add a double to this line and recompile
  406. your Apache server. The correct block of code is:</p>
  407. <pre>
  408. union align
  409. {
  410. /* Types which are likely to have the longest RELEVANT alignment
  411. * restrictions... we don't do much with doubles.
  412. */
  413. char *cp;
  414. void (*f)();
  415. long l;
  416. FILE *fp;
  417. double d;
  418. };
  419. </pre>
  420. <p>These problems have all been fixed in later versions of
  421. Apache.</p>
  422. <p>Check the Apache documentation on how to add a module.
  423. Generally you add the module name to a file called
  424. <em>Configuration</em>. The line to be added if you want to
  425. use the mod_actions module is:</p>
  426. <p><tt>Module action_module mod_actions.o</tt></p>
  427. <p>If you are using the mod_cgi_redirect.c module add this
  428. line:</p>
  429. <p><tt>Module cgi_redirect_module mod_cgi_redirect.o</tt></p>
  430. <p>Then compile your httpd and install it. To configure the
  431. cgi redirection you need to either create a new mime type in
  432. your <em>mime.types</em> file or you can use the
  433. <strong>AddType</strong> command in your <em>srm.conf</em>
  434. file to add the mime type. The mime type to be added should
  435. be something like this:</p>
  436. <p><tt>application/x-httpd-php phtml</tt></p>
  437. <p>If you are using the mod_actions.c module you need to add
  438. the following line to your <em>srm.conf</em> file:</p>
  439. <p><tt>Action application/x-httpd-php
  440. /cgi-bin/php.cgi</tt></p>
  441. <p>If you are using mod_cgi_redirect.c you should add this
  442. line to <em>srm.conf</em>:</p>
  443. <p><tt>CgiRedirect application/x-httpd-php
  444. /cgi-bin/php.cgi</tt></p>
  445. <p>Don't try to use both mod_actions.c and mod_cgi_redirect.c
  446. at the same time.</p>
  447. <p>Once you have one of these cgi redirection modules
  448. installed and configured correctly, you will be able to
  449. specify that you want a file parsed by php/fi simply by
  450. making the file's extension <strong>.phtml</strong>.
  451. Furthermore, if you add <strong>index.phtml</strong> to your
  452. <strong>DirectoryIndex</strong> configuration line in your
  453. <em>srm.conf</em> file then the top-level page in a directory
  454. will be automatically parsed by php if your index file is
  455. called index.phtml.</p>
  456. </dd>
  457. <dt><strong>Netscape HTTPD</strong></dt>
  458. <dd>
  459. <p>You can automatically redirect requests for files with a
  460. given extension to be handled by PHP/FI by using the Netscape
  461. Server CGI Redirection module. This module is available in
  462. the <a href="http://php.iquest.net/files/">File Archives</a>
  463. on the <a href="http://php.iquest.net/">PHP/FI Home Page</a>.
  464. The README in the package explicitly explains how to
  465. configure it for use with PHP/FI.</p>
  466. </dd>
  467. <dt><strong>NCSA HTTPD</strong></dt>
  468. <dd>
  469. <p>NCSA does not currently support modules, so in order to do
  470. cgi redirection with this server you need to modify your
  471. server source code. A patch to do this with NCSA 1.5 is
  472. available in the <a href=
  473. "http://php.iquest.net/files/">PHP/FI file archives</a>.</p>
  474. </dd>
  475. </dl>
  476. <hr />
  477. <h2><a name="security" id="security">Security Issues</a></h2>
  478. <p>The CGI version of PHP/FI does <strong>not</strong> read any
  479. <em>.htaccess</em> files which may be present in a directory.
  480. This means that if you have files that are protected using the
  481. standard .htaccess server-based access control feature, people
  482. could potentially circumvent this security by loading the page
  483. through PHP/FI. Note that this is not an issue for the Apache
  484. module version of PHP/FI.</p>
  485. <p>A second problem with the CGI version is that if it is placed
  486. in the system's cgi-bin directory it can be used to view any file
  487. on your system as long as the user id it runs as has access to
  488. it.</p>
  489. <p>There are a couple of different solutions to this problem. The
  490. easiest is probably to use the <strong>PATTERN_RESTRICT</strong>
  491. feature found in <em>php.h</em>. This lets you define an
  492. extension (or a pattern of extensions) which are allowed to be
  493. parsed by PHP/FI. If a file does not have this extension and
  494. someone tries to load it with PHP/FI, an <em>access denied</em>
  495. message will appear.</p>
  496. <p>Another solution is to use the PHP/FI access control mechanism
  497. to mimic the access control setup you have in your .htaccess
  498. file. Keeping this information in two places can be tedious
  499. though, and the two systems don't share all of the same
  500. features.</p>
  501. <p>The problem can also be solved using file permissions. PHP/FI
  502. can be set up to run setuid as any user you wish. Then files that
  503. are to be read by PHP/FI can be given appropriate permissions and
  504. files not to be read by PHP/FI should be owned by another user id
  505. and have their permissions changed accordingly.</p>
  506. <p>For additional security options related to sites which provide
  507. shared access to PHP, see the <a href="#safemode">Safe Mode</a>
  508. section.</p>
  509. <hr />
  510. <h2><a name="safemode" id="safemode">Safe Mode</a></h2>
  511. <p>PHP's Safe Mode tries to solve the common problem faced by
  512. many ISP's regarding letting all their users run CGI programs.
  513. The common mechanism for making shared CGI access more secure is
  514. to use a cgi wrapper like the su_exec utility that comes with
  515. Apache. This will not work for PHP when it is running as a module
  516. because it is not a separate process that can be setuid'ed.</p>
  517. <p>It is based on a file permission scheme. Simply put, if a file
  518. is either owned by the same user id as the script that is trying
  519. to access it, or if the file is in a directory that is owned by
  520. the same user as the script that is trying to access it, then the
  521. access is allowed. One caveat here is that you must make sure
  522. that your OS does not allow non-root user to chown away the
  523. ownership on one of their files. Many older SysV systems allow
  524. this. The most common one is Irix. It is possible to change this
  525. behaviour at the OS level on Irix.</p>
  526. <p>Safe Mode applies to each function which could possibly be a
  527. security risk. Below is the current list of checks applied to
  528. each relevant function. In the following list, PHP UID refers to
  529. the user id of the owner of the current file being parsed by PHP,
  530. and HTTP UID refers to the user id the httpd process is running
  531. as (usually nobody).</p>
  532. <dl>
  533. <dt>Include, ReadFile, Fopen, File, Link, Unlink, Symlink,
  534. Rename, RmDir, ChMod, ChOwn, ChGrp</dt>
  535. <dd>Owner of file to be included must either be the PHP UID or
  536. the directory in which the file resides must be owned by the
  537. PHP UID.</dd>
  538. <dt>Exec, System, PassThru and Popen</dt>
  539. <dd>Executables to be forked and executed must reside in the
  540. directory defined by the PHP_SAFE_MODE_EXEC_DIR #define in
  541. php.h when PHP is compiled.</dd>
  542. <dt>Mysql_Connect</dt>
  543. <dd>This function takes an optional username to use to connect
  544. to an MySQL database. When in safe mode, this username must
  545. either be the username of the owner of the current file being
  546. parsed, or the name of the httpd user (usually nobody).</dd>
  547. <dt>HTTP Authentication</dt>
  548. <dd>The numerical user id of the owner of the script containing
  549. the HTTP Authentication code will be prepended to the
  550. authentication realm. This is to prevent someone from writing a
  551. password grabbing script which spoofs another authenticated
  552. page on the same server.</dd>
  553. </dl>
  554. <hr />
  555. <h2><a name="commandline" id="commandline">Running PHP/FI from
  556. the command line</a></h2>
  557. <p>If you build the CGI version of PHP/FI, you can use it from
  558. the command line simply typing: <tt>php.cgi filename</tt> where
  559. filename is the file you want to parse. You can also create
  560. standalone PHP/FI scripts by making the first line of your script
  561. look something like:</p>
  562. <pre>
  563. #!/usr/local/bin/php.cgi -q
  564. </pre>The "-q" suppresses the printing of the HTTP headers. You can
  565. leave off this option if you like.
  566. <hr />
  567. <h2><a name="http_auth" id="http_auth">HTTP
  568. Authentication</a></h2>
  569. <p>The HTTP Authentication hooks in PHP/FI are only available
  570. when it is running as an Apache module. In an Apache module
  571. PHP/FI script, it is possible to use the Header() command to send
  572. an "Authentication Required" message to the client browser
  573. causing it to pop up a Username/Password input window. Once the
  574. user has filled in a username and a password, the URL containing
  575. the PHP/FI script will be called again with the variables,
  576. $PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE set to the user
  577. name, password and authentication type respectively. Only "Basic"
  578. authentication is supported at this point.</p>
  579. <p>An example script fragment which would force client
  580. authentication on a page would be the following:</p>
  581. <pre>
  582. &lt;?
  583. if(!$PHP_AUTH_USER) {
  584. Header("WWW-authenticate: basic realm=\"My Realm\"");
  585. Header("HTTP/1.0 401 Unauthorized");
  586. echo "Text to send if user hits Cancel button\n"
  587. exit;
  588. } else {
  589. echo "Hello $PHP_AUTH_USER.&lt;P&gt;";
  590. echo "You entered $PHP_AUTH_PW as your password.&lt;P&gt;";
  591. }
  592. &gt;
  593. </pre>
  594. <p>Instead of simply printing out the $PHP_AUTH_USER and
  595. $PHP_AUTH_PW, you would probably want to check the username and
  596. password for validity. Perhaps by sending a query to a database,
  597. or by looking up the user in a dbm file.</p>
  598. <p>Watch out for buggy Internet Explorer browsers out there. They
  599. seem very picky about the order of the headers. Sending the
  600. <b>WWW-authenticate</b> header before the <b>HTTP/1.0 401</b>
  601. header seems to do the trick for now.</p>
  602. <p>In order to prevent someone from writing a script which
  603. reveals the password for a page that was authenticated through a
  604. traditional external mechanism, the PHP_AUTH variables will not
  605. be set if external authentication is enabled for that particular
  606. page.</p>
  607. <p>Note however that the above does not prevent someone who
  608. controls a non-authenticated URL from stealing passwords from
  609. authenticated URL's on the same server. The PHP_AUTH_VARS define
  610. in <em>php.h</em> can be undefined to make sure that these
  611. variables will never be set and thus disable anybody from using
  612. mod_php to try to steal passwords.</p>
  613. <hr />
  614. <h2><a name="requestvars" id="requestvars">Apache Request
  615. Variables</a></h2>
  616. <p>When running PHP as an Apache module, you may access the
  617. request header variables sent by the remote browser by prepending
  618. <b>$req_</b> to the beginning of the header value you would like
  619. to use. If the request name contains a <b>-</b> character such as
  620. User-Agent, then you need to map the - to _ (an underscore). ie.
  621. reference it as $req_User_Agent. The <a href=
  622. "#phpinfo">phpinfo()</a> function can be used to display all the
  623. request headers.</p>
  624. <p>eg.</p>
  625. <pre>
  626. &lt;
  627. echo "$req_connection&lt;br&gt;";
  628. echo "$req_host&lt;br&gt;";
  629. &gt;
  630. </pre>The above simple script might output:
  631. <pre>
  632. Keep-Alive
  633. www.host.com
  634. </pre>
  635. <hr />
  636. <h2><a name="module" id="module">Apache Module Notes</a></h2>
  637. <p>Running PHP/FI as an Apache module is the most efficient way
  638. of using the package. Running it as a module means that the
  639. PHP/FI functionality is combined with the Apache server's
  640. functionality in a single program. There are a number of
  641. advantages to running it as a module:</p>
  642. <dl>
  643. <dt><strong>Performance</strong></dt>
  644. <dd>
  645. <p>Performance-wise it is a lot faster than traditional CGI
  646. programs. In fact, when running PHP/FI as a module, there is
  647. no CGI involved. The script code in the HTML files is
  648. executed directly by the Apache web server process.</p>
  649. </dd>
  650. <dt><strong>Security</strong></dt>
  651. <dd>
  652. <p>When running as a module, the normal httpd-based access
  653. restriction rules defined either in the Apache conf files or
  654. in private .htaccess files are first applied before the
  655. module is allowed to parse the file. Alternatively, you can
  656. also create PHP/FI scripts that control the normal
  657. httpd-based authentication. See <a href="#http_auth">HTTP
  658. Authentication</a>.</p>
  659. </dd>
  660. <dt><strong>Configurability</strong></dt>
  661. <dd>
  662. <p>Since the parser is always active inside the httpd
  663. process, it can be configured on startup using the same
  664. configuration files used to configure the httpd process. The
  665. module can even be configured on a per-directory basis by
  666. placing the <a href="#directives">PHP configuration
  667. directives</a> in the <em>.htaccess</em> files.</p>
  668. </dd>
  669. <dt><strong>Basis for custom server-based
  670. function</strong></dt>
  671. <dd>
  672. <p>For C programmers interested in accessing their functions
  673. from within Apache, the PHP/FI framework provides a very
  674. simple interface to Apache and to PHP itself. It is much
  675. easier to add a function to PHP and call that from a parsed
  676. page than it is to write an entire Apache module from
  677. scratch. See the <a href="#addfunc">Adding your own internal
  678. functions to PHP/FI</a> sections at the end of this document
  679. for further details.</p>
  680. </dd>
  681. </dl>
  682. <h2><a name="directives" id="directives">Apache Module
  683. Configuration Directives</a></h2>
  684. <p>The following directives can be placed either in the
  685. <em>srm.conf</em> file, or within
  686. &lt;Directory&gt;...&lt;/Directory&gt; tags in
  687. <em>access.conf</em> or in &lt;Location
  688. /path&gt;...&lt;/Location&gt; tags in <em>access.conf</em> or in
  689. individual <em>.htaccess</em> files. In order for the directives
  690. to work in .htaccess files, the Options override must be set on
  691. the AllowOverride Apache directive, with the exception of the
  692. phpEngine directive which is only available in the *.conf
  693. files.</p>
  694. <dl>
  695. <dt><strong>phpShowInfo <em>on</em>|<em>off</em></strong></dt>
  696. <dd>Turn the PHP info footers on or off. Default is on.</dd>
  697. <dt><strong>phpLogging <em>on</em>|<em>off</em></strong></dt>
  698. <dd>Turn logging on or off. Default is on.</dd>
  699. <dt><strong>phpDebug <em>on</em>|<em>off</em></strong></dt>
  700. <dd>Turn automatic ?info debug screen on or off. Default is
  701. off.</dd>
  702. <dt><strong>phpUploadTmpDir <em>directory</em></strong></dt>
  703. <dd>Set the directory where form-uploaded files will be
  704. placed.</dd>
  705. <dt><strong>phpDbmLogDir <em>directory</em></strong></dt>
  706. <dd>Set the directory where dbm-based logging files will be
  707. written.</dd>
  708. <dt><strong>phpSQLLogDB <em>database</em></strong></dt>
  709. <dd>Set name of SQL database to use for logging. Default is
  710. "phpfi"</dd>
  711. <dt><strong>phpSQLLogHost <em>hostname</em></strong></dt>
  712. <dd>Set hostname where SQL database to use for logging is
  713. found. Default is localhost.</dd>
  714. <dt><strong>phpAccessDir <em>directory</em></strong></dt>
  715. <dd>Set the directory where PHP-internal access control files
  716. are stored.</dd>
  717. <dt><strong>phpMaxDataSpace <em>KiloBytes</em></strong></dt>
  718. <dd>Max size a sub-pool can grow to within the PHP module.
  719. Setting this value to a low number will minimize the impact
  720. that mod_php will have on your system, but it may also limit
  721. people from writing complex scripts. The default is 8K.</dd>
  722. <dt><strong>phpIncludePath <em>colon-separated
  723. path</em></strong></dt>
  724. <dd>A colon-separated list of directories where php will look
  725. for files in when running <a href="#include">include()</a>. The
  726. default is to look only in the current directory.</dd>
  727. <dt><strong>phpAutoPrependFile <em>file name</em></strong></dt>
  728. <dd>Before the actual PHP/FI file is parsed, you may give a
  729. file name here that is parsed before the "main file", using
  730. PHP's Include() function (which means phpIncludePath applies
  731. for the file name). Keep in mind that you can make it difficult
  732. for yourself to use the Header() function in the main file if
  733. you write HTML from an auto-prepended file.</dd>
  734. <dt><strong>phpAutoAppendFile <em>file name</em></strong></dt>
  735. <dd>The name of a file parsed (using PHP's Include()
  736. function)after the actual PHP/FI file has been parsed, similar
  737. to phpAutoPrependFile.</dd>
  738. <dt><strong>phpAdaDefDB <em>database</em></strong></dt>
  739. <dd>Default Adabas database to use. No default value</dd>
  740. <dt><strong>phpAdaUser <em>username</em></strong></dt>
  741. <dd>Default Adabas database user. No default value</dd>
  742. <dt><strong>phpAdaPW <em>password</em></strong></dt>
  743. <dd>Default Adabas database password. No default value</dd>
  744. <dt><strong>phpEngine <em>on</em>|<em>off</em></strong></dt>
  745. <dd>Turn the PHP parsing engine on or off. The default is
  746. <em>on</em> and this directive is only useful for sites that
  747. wish to allow directives from the AllowOverride Options list of
  748. directives to function in .htaccess files while at the same
  749. time restricting mod_php access. The common way to handle
  750. per-virtual host php installs is to enable the PHP mime type
  751. with an AddType directive on a per virtual host basis and then
  752. put "phpEngine off" in the non-PHP virtual host blocks. If a
  753. non PHP customer tries to circumvent things by placing the PHP
  754. mime type in their .htaccess, the phpEngine off setting
  755. restricts the PHP parser from functioning.</dd>
  756. <dt><strong>phpLastModified
  757. <em>on</em>|<em>off</em></strong></dt>
  758. <dd>Since php pages are dynamic, they are processed and sent to
  759. the browser each time you access them. But sometimes, when you
  760. use php for basic includes, the parsed page does not change as
  761. long as the source doesn't. It that case, you may want to avoid
  762. page regeneration/reloading. If phpLastModified is turned on
  763. Apache will send the Last-Modified tag to the browser, so that
  764. the page will only be reloaded when it changes. (not that if
  765. you are using page logging, multiple accesses will not be
  766. logged!)</dd>
  767. </dl>
  768. <p>All of these directives are optional. If a directive is not
  769. specified anywhere, the compile-time default will be used.</p>
  770. <hr />
  771. <h2><a name="fastcgi" id="fastcgi">FastCGI Support</a></h2>
  772. <p>PHP/FI can be compiled with FastCGI support. You will need
  773. fetch and compile <a href="http://www.fastcgi.com">FCGI
  774. Development Kit</a> for your platform before compiling PHP/FI.
  775. You will also need to get <a href="#redirect">CGI Redirection</a>
  776. working. Then follow the instructions in the FastCGI
  777. documentation for configuring FastCGI for your platform. If you
  778. are using the mod_fastcgi module with the Apache server, here are
  779. the step-by-step instructions:</p>
  780. <ul>
  781. <li>Edit your Apache Configuration file and add the mod_fastcgi
  782. module, then recompile Apache.</li>
  783. <li>Edit your <em>srm.conf</em> file and add lines similar
  784. to:<br />
  785. <tt>AddType application/x-httpd-fcgi .fcgi<br />
  786. AppClass /usr/local/etc/httpd/fcgi-bin/php.fcgi -processes
  787. 4<br />
  788. AddType application/x-httpd-fphp .fhtml<br />
  789. Action application/x-httpd-fphp
  790. /fcgi-bin/php.fcgi<br /></tt></li>
  791. <li>Copy your <em>php.cgi</em> binary to
  792. <em>/usr/local/etc/httpd/fcgi-bin/php.fcgi</em></li>
  793. </ul>
  794. <p>Now, any pages with the .fhtml extension will be handed off to
  795. the FastCGI php.fcgi process which is already running. The
  796. php.fcgi binary will still work as a normal CGI binary, so you
  797. could just create a symbolic link from php.cgi to php.fcgi.</p>
  798. <p>If you are not using Apache, the above steps will be similar,
  799. but not identical. CGI Redirection mechanisms are available for
  800. NCSA and Netscape servers at the <a href=
  801. "http://php.iquest.net/files/">PHP/FI File Archive</a>.</p>
  802. <hr />
  803. <h2><a name="access" id="access">Access Control</a></h2>
  804. <p>Note that the built-in PHP/FI based access control is likely
  805. to be discontinued in future versions. You should seriously
  806. consider using the security mechanism that comes with your web
  807. server instead.</p>
  808. <p>If you chose to include access control when you compiled the
  809. package, you may append <em>?config</em> to any URL to edit the
  810. access control file. ie.</p>
  811. <p>
  812. <tt>http://your.machine.domain/cgi-bin/php.cgi/path/file.html?config</tt></p>
  813. <p>Your configuration password will initially be set to your user
  814. id. If your user id does not work as your password, it probably
  815. means that PHP could not read the /etc/passwd file to locate your
  816. user id. If this is the case, the initial password will be set to
  817. "<strong>php</strong>". It is a good idea to change this
  818. password. Note that multiple users may maintain their own
  819. personal configuration files through a single PHP/FI binary.</p>
  820. <p>Access Control can be quite confusing initially. The ?config
  821. screen is divided up into a number of sections. The top section
  822. is for changing the password used to make sure that only people
  823. who know this password can change access control characteristics.
  824. In a system-wide installation, each user has his or her own
  825. configuration screen with his or her own password.</p>
  826. <p>The second section of the ?config screen consists of a number
  827. of tables. Each table defines a rule-set. The first rule-set is
  828. always the default rule-set. This default rule-set is used if a
  829. page does not have a rule-set defined specifically for it. After
  830. the default rule-set, any number of specific rule-set tables will
  831. follow.</p>
  832. <p>To add a rule-set for a specific file, enter the URL of the
  833. file in your browser and add <em><strong>?config</strong></em> to
  834. the end of the URL. On the ?config screen that comes up you will
  835. see that a rule-set has been added for this page, if it wasn't
  836. already there. When a new rule-set is added, it is initially set
  837. to be the same as the default rule-set. The following picture
  838. shows two simple rule-sets. First a default rule-set which just
  839. indicates that hits from all domains should be logged, and
  840. second, for the file /~rasmus/test.html and only that file, any
  841. users coming from a "<em>.edu</em>" domain will not be granted
  842. access.</p>
  843. <p><img src="gifs/config.gif" alt=
  844. "[Image of ?config screen]" /></p>
  845. <p>To edit a rule-set modify the fields until the desired
  846. configuration is reached within a rule-set and then hit the
  847. "<em>Submit Changes</em>" button. If more rules are needed, hit
  848. the "<em>Add Rule</em>" button and then edit the added rule.</p>
  849. <p>To delete a rule, select the checkbox to the right of the rule
  850. and hit the "<em>Submit Changes</em>" button. The screen will
  851. redraw and the rule should disappear.</p>
  852. <p>Note that you need to enter a regular expression in the
  853. pattern field. See the section on regular expressions in this
  854. documentation for more details.</p>
  855. <hr />
  856. <h2><a name="logging" id="logging">Access Logging</a></h2>
  857. <p>Access Logging is another optional feature which can be
  858. enabled at compile-time by answering <em>Yes</em> to the question
  859. in the install script. You may either store your access log data
  860. in dbm files, in an mSQL database, or in an mysql database. The
  861. latter two are more powerful, but is also a bit more difficult to
  862. set up.</p>
  863. <p>To use dbm files for storing your access logs, you will need
  864. to specify a directory in which log files can be written. PHP
  865. will try to create this directory if it doesn't exist, but to
  866. make sure it has the proper permissions, you may want to create
  867. this directory yourself before running PHP for the first time.
  868. The permissions on the directory should be such that the user id
  869. under which the PHP cgi program will run can write to the
  870. directory.</p>
  871. <p>To use an mSQL or mysql database for storing your access log
  872. data, you need to first make sure you have mSQL or mysql
  873. installed and running on your system. Then you need to create a
  874. database. The default name is "phpfi" although this can be
  875. changed in <em>src/php.h</em>. To create this database for mSQL,
  876. type:</p>
  877. <pre>
  878. msqladmin create phpfi
  879. </pre>
  880. <p>or for mysql type:</p>
  881. <pre>
  882. mysqladmin create phpfi
  883. </pre>
  884. <p>Then for mSQL, edit your <em>msql.acl</em> file and make sure
  885. the permissions on the database are correct. Something like the
  886. following should suffice:</p>
  887. <pre>
  888. database=phpfi
  889. read=*
  890. write=nobody,&lt;your user id&gt;
  891. access=local
  892. </pre>
  893. <p>For mysql, you need to make sure the httpd user (usually
  894. "nobody") has access to the database. Unlike mSQL, mysql stores
  895. access control data in a database. Assuming default permissions,
  896. you should be able to simply execute the following command:</p>
  897. <pre>
  898. echo "INSERT INTO user VALUES ('localhost','nobody','','Y','Y','Y','Y','Y','Y','Y','Y','Y');" | mysql mysql
  899. </pre>
  900. <p>Don't forget to load this new configuration with:</p>
  901. <pre>
  902. mysqladmin reload
  903. </pre>
  904. <p>For each user id for whom you want to store log data, you need
  905. to create two tables. The <em>msqllog</em> shell script in the
  906. scripts directory will do this for you. Simply type:</p>
  907. <pre>
  908. msqllog &lt;user id&gt;
  909. </pre>
  910. <p>or for mysql, type:</p>
  911. <pre>
  912. mysqllog &lt;user id&gt;
  913. </pre>
  914. <p>and the script will create the appropriate tables. You may
  915. need to edit the script to make it reflect where things are
  916. stored on your system.</p>
  917. <p>You may want to have a look at this script. It defines the
  918. field sizes of your log tables. If, for example, you know that
  919. your file paths exceed 64 characters, you need to bump up the
  920. filename size in both the <em>logN</em> and the <em>lastN</em>
  921. tables in this <em>msqllog</em> or <em>mysqllog</em> file.</p>
  922. <p>Access logging stores information about each "hit" on a page.
  923. This information can then be summarized by examining these log
  924. files. An example log file summarizing script is included in the
  925. package. It is the <tt>log.html</tt> file in the
  926. <tt>examples</tt> directory. This is the dbm log file analyzer.
  927. The mSQL log file analyzer is called <tt>mlog.html</tt>. And the
  928. mysql log file analyzer is called <tt>mylog.html</tt>. To run it,
  929. copy it and the other mlog.* files to a directory accessible from
  930. your web server and type:</p>
  931. <pre>
  932. http://your.machine.domain/cgi-bin/php.cgi/path/mlog.html
  933. </pre>
  934. <p>Or, if you are using the Apache module version, you can give
  935. the script a ".phtml" extension and call it with:</p>
  936. <pre>
  937. http://your.machine.domain/path/mlog.phtml
  938. </pre>
  939. <p>By default, if you have compiled PHP with access logging
  940. enabled, then your pages will appear with a footer containing
  941. some access information. You may not want to see this footer, but
  942. still log hits. You can turn off this footer with a "phpShowInfo
  943. off" line in your Apache httpd.conf or .htaccess files if you are
  944. running Apache. If you are not running Apache, you may turn these
  945. log footers off either by creating a rule in the <a href=
  946. "#access">?config</a> section for the page, or by adding a tag
  947. like this to your page:</p>
  948. <p><tt>&lt;?setshowinfo(0)&gt;</tt></p>
  949. <hr />
  950. <h2><a name="relative" id="relative">Relative vs. Absolute URL's
  951. - or, Why do my Images Break?</a></h2>
  952. <p>A problem common to all CGI wrappers is that the HTTPD program
  953. changes the current directory to the directory where whatever it
  954. is loading is stored. In the case of a CGI program, the current
  955. directory is set to the directory where the CGI program resides.
  956. This is normally not a problem, except when it comes to relative
  957. URL's.</p>
  958. <p>A relative URL is a URL which relies upon the current
  959. directory being the same as the directory where the current HTML
  960. file is located. So, for example, if I had the URL:</p>
  961. <pre>
  962. http://my.machine/~rasmus/file.html
  963. </pre>
  964. <p>the actual HTML file might be:</p>
  965. <pre>
  966. ~rasmus/public_html/file.html
  967. </pre>
  968. <p>If within the <tt>file.html</tt> file I had the tag:</p>
  969. <pre>
  970. &lt;IMG SRC="pic.gif"&gt;
  971. </pre>
  972. <p>when loaded normally this file gif file is expected to be in
  973. <tt>~rasmus/public_html/pic.gif</tt>. However, when loaded
  974. through a CGI wrapper with a URL like:</p>
  975. <pre>
  976. http://my.machine/cgi-bin/php.cgi/~rasmus/file.html
  977. </pre>
  978. <p>then HTTPD sets the current directory to <tt>/cgi-bin</tt> (or
  979. wherever the ScriptAlias might point) and subsequently when the
  980. page is loaded the <tt>pic.gif</tt> file is expected to be in:
  981. <tt>/cgi-bin/pic.gif</tt> which is usually not the desired
  982. effect.</p>
  983. <p>The quick way around this problem is to use absolute URL's. In
  984. the above example if the image tag had been:</p>
  985. <pre>
  986. &lt;IMG SRC="/~rasmus/pic.gif"&gt;
  987. </pre>
  988. <p>then there would have been no problem. Using absolute URL's is
  989. not always desirable as it makes pages less portable. An obvious
  990. question you may have at this point is, "Why doesn't PHP just
  991. change the current directory to the right place?". The answer is
  992. that PHP actually does change the current directory to the
  993. location of the HTML file it is displaying. Any file paths used
  994. inside PHP Script tags, can be relative. The problem is that tags
  995. outside of PHP's control such as &lt;img &gt; and &lt;a href &gt;
  996. will not be passed through PHP. When they are parsed, PHP is no
  997. longer active and the current working directory has been set back
  998. to the directory specified by the HTTP Daemon.</p>
  999. <p><strong>The Solution</strong> is a compromise. PHP provides a
  1000. variable called <strong>PATH_DIR</strong>. It contains the
  1001. directory portion of the current HTML file at all times. If this
  1002. PATH_DIR variable is used in the &lt;img &gt; and &lt;a href &gt;
  1003. tags then the effect of a relative URL can be achieved, although
  1004. to the server it will look like an absolute URL when parsed. From
  1005. our above example, the only change we would need to make would be
  1006. to change the img tag to:</p>
  1007. <pre>
  1008. &lt;IMG SRC="&lt;?echo $PATH_DIR&gt;/pic.gif"&gt;
  1009. </pre>By using the above, you can move the file containing this tag
  1010. around, and the tag will always refer to a <tt>pic.gif</tt> file in
  1011. the same directory as the source HTML file.
  1012. <p>Another way to handle this is to use the traditional &lt;BASE
  1013. HREF=...&gt; in the HTML file.</p>
  1014. <hr />
  1015. <h2><a name="getpost" id="getpost">How PHP handles GET and POST
  1016. method data</a></h2>
  1017. <p>PHP will detect both GET and POST method data coming from HTML
  1018. forms. One important point to understand is that POST method data
  1019. is always treated first if both are present. If a PHP variable is
  1020. defined by the POST method data, or if the variable is defined by
  1021. the HTTP daemon in the Unix environment, then GET method data
  1022. cannot overwrite it. This is to prevent somebody from adding
  1023. <em>?REMOTE_HOST=some.bogus.host</em> to their URL's and thus
  1024. tricking the PHP logging mechanism into recording this alternate
  1025. data. POST method data is however allowed to overwrite these
  1026. variables.</p>
  1027. <p>Any component of the GET data (the data following a '?' in the
  1028. URL) which is of the form, <em>word=something</em> will define
  1029. the variable <em>$word</em> to contain the value
  1030. <em>something</em>. Even if the data is not of this form, it can
  1031. be accessed with the $argv built-in array. For example, in a URL
  1032. like:</p>
  1033. <pre>
  1034. /cgi-bin/php.cgi/file.html?abc+def+EMAIL_ADDR=rasmus@lerdorf.on.ca&amp;var=value
  1035. </pre>The relevant components of the PHP symbol table will be:
  1036. <pre>
  1037. $argc = 4
  1038. $argv[0] = abc
  1039. $argv[1] = def
  1040. $argv[2] = EMAIL_ADDR=rasmus@lerdorf.on.ca&amp;var=value
  1041. $EMAIL_ADDR = rasmus@lerdorf.on.ca
  1042. $var = value
  1043. </pre>
  1044. <p>Notice how the EMAIL_ADDR part of the data shows up both as
  1045. $argv[2] where it is unparsed, and the $EMAIL_ADDR variable is
  1046. created to contain <em>rasmus@lerdorf.on.ca</em>.</p>
  1047. <p>The $EMAIL_ADDR variable was used as an example in the above
  1048. because it is a useful variable if you are using the logging
  1049. features of PHP. By adding:</p>
  1050. <pre>
  1051. ?EMAIL_ADDR=
  1052. </pre>
  1053. <p>to any links on a page where the user's email address is
  1054. known, you may propagate it to the next page. The PHP logging
  1055. system will automatically look for this variable and record its
  1056. value as the user's e-mail address in the logs. For any users of
  1057. PHP1, the above serves the same function as adding
  1058. <em>?&lt;!--$email--&gt;</em> to the URL used to do in PHP1. It
  1059. looks a little bit more complex now, but it is also completely
  1060. general allowing you to build your own complex pages.</p>
  1061. <p>In the above example you can also see how multiple variables
  1062. can be defined right in the GET method data by separating each
  1063. with the "&amp;" character. This "&amp;" separated list of
  1064. variables must be the last (or only) component of the GET method
  1065. data for it to be valid.</p>
  1066. <p><a name="selmul" id="selmul"><strong><tt>SELECT MULTIPLE</tt>
  1067. and PHP</strong></a></p>
  1068. <p>The SELECT MULTIPLE tag in an HTML construct allows users to
  1069. select multiple items from a list. These items are then passed to
  1070. the action handler for the form. The problem is that they are all
  1071. passed with the same widget name. ie.</p>
  1072. <pre>
  1073. &lt;SELECT NAME="var" MULTIPLE&gt;
  1074. </pre>
  1075. <p>Each selected option will arrive at the action handler as:</p>
  1076. <p>var=option1<br />
  1077. var=option2<br />
  1078. var=option3</p>
  1079. <p>Each option will overwrite the contents of the previous $var
  1080. variable. The solution is to use PHP/FI's non-indexed array
  1081. feature. The following should be used:</p>
  1082. <pre>
  1083. &lt;SELECT NAME="var[]" MULTIPLE&gt;
  1084. </pre>
  1085. <p>This tells PHP/FI to treat <em>var</em> as an array an each
  1086. assignment of a value to var[] adds an item to the array. The
  1087. first item becomes $var[0], the next $var[1], etc. The <a href=
  1088. "#count">count()</a> function can be used to determine how many
  1089. options were selected, and the <a href="#sort">sort()</a>
  1090. function can be used to sort the option array if necessary.</p>
  1091. <hr />
  1092. <a name="imagecoord" id="imagecoord"><strong><tt>IMAGE
  1093. SUBMIT</tt> and PHP</strong></a>
  1094. <p>When submitting a form, it is possible to use an image instead
  1095. of the standard submit button with a tag like:</p>
  1096. <pre>
  1097. &lt;input type=image src=image.gif name=sub&gt;
  1098. </pre>
  1099. <p>When the user clicks somewhere on the image, the accompanying
  1100. form will be transmitted to the server with two additional
  1101. variables, <em>sub_x</em> and <em>sub_y</em>. These contain the
  1102. coordinates of the user click within the image. The experienced
  1103. may note that the actual variable names sent by the browser
  1104. contains a period rather than an underscore, but PHP converts the
  1105. period to an underscore automatically.</p>
  1106. <hr />
  1107. <h2><a name="gd_support" id="gd_support">GD (a graphics library
  1108. for GIF creation) Support in PHP</a></h2>PHP supports the GD
  1109. library version 1.2 written by Thomas Boutell. There is no GD
  1110. code in PHP itself. If you wish to use the GD support in PHP/FI,
  1111. you must obtain the GD library from <a href=
  1112. "http://www.boutell.com/gd/http/gd1.3.tar.gz">http://www.boutell.com/gd/http/gd1.3.tar.gz</a>,
  1113. install it, and then re-install PHP.
  1114. <p>Not all of the GD features are supported by PHP. For a list of
  1115. supported functions see the <a href="#funcs">Alphabetical List of
  1116. Functions</a>. All the GD functions start with the word,
  1117. <em>Image</em>.</p>
  1118. <p>More information on the GD package is available at: <a href=
  1119. "http://www.boutell.com/gd/">http://www.boutell.com/gd/</a>.</p>
  1120. <p><em>GD 1.2 is copyright 1994, 1995 Quest Protein Database
  1121. Center, Cold Springs Harbor Labs.</em></p>
  1122. <hr />
  1123. <h2><a name="virtual_hosts" id="virtual_hosts">PHP/FI and Virtual
  1124. Hosts</a></h2>PHP works fine on virtual host setups supported by
  1125. some http daemons. The one problem that may occur on such a setup
  1126. is related to an inconsistency in the way httpd sets the
  1127. SCRIPT_NAME environment variable. Normally it is set to the path
  1128. of the current CGI program in relation to the top-level ROOT_DIR
  1129. on the httpd server. However, when a virtual domain is used, some
  1130. httpd's do not correctly set the SCRIPT_NAME variable as the
  1131. relative path from the virtual domain's top level directory as it
  1132. should. If the ?config screen gives you an invalid URL error
  1133. message, you know that this problem exists on your setup. You
  1134. will need to edit the <em>php.h</em> file and set the
  1135. VIRTUAL_PATH #define to the path to your <em>php.cgi</em> binary
  1136. relative to your top-level directory.
  1137. <hr />
  1138. <h2><a name="upload" id="upload">File Upload Support</a></h2>
  1139. <p>PHP/FI will automatically detect a file upload from a browser
  1140. which supports the form-based file upload features as proposed by
  1141. <a href="mailto:nebel@xsoft.sd.xerox.com">E. Nebel</a> and
  1142. <a href="mailto:masinter@parc.xerox.com">L. Masinter</a> from
  1143. Xerox and described in <a href=
  1144. "ftp://ds.internic.net/rfc/rfc1867.txt">RFC 1867</a>.</p>
  1145. <p>A file upload screen can be built by creating a special form
  1146. which looks something like this:</p>
  1147. <blockquote>
  1148. <pre>
  1149. &lt;FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST&gt;<br />
  1150. &lt;INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000"&gt;<br />
  1151. Send this file: &lt;INPUT NAME="userfile" TYPE="file"&gt;<br />
  1152. &lt;INPUT TYPE="submit" VALUE="Send File"&gt;<br />
  1153. &lt;/FORM&gt;
  1154. </pre>
  1155. </blockquote>
  1156. <p>The _URL_ should point to a php html file. The MAX_FILE_SIZE
  1157. hidden field must precede the file input field and its value is
  1158. the maximum filesize accepted. The value is in bytes. In this
  1159. destination file, the following variables will be defined upon a
  1160. successful upload:</p>
  1161. <dl>
  1162. <dt><strong>$userfile</strong></dt>
  1163. <dd>
  1164. <p>The temporary filename in which the uploaded file was
  1165. stored on the server machine.</p>
  1166. </dd>
  1167. <dt><strong>$userfile_name</strong></dt>
  1168. <dd>
  1169. <p>The original name of the file on the sender's system.</p>
  1170. </dd>
  1171. <dt><strong>$userfile_size</strong></dt>
  1172. <dd>
  1173. <p>The size of the uploaded file in bytes.</p>
  1174. </dd>
  1175. <dt><strong>$userfile_type</strong></dt>
  1176. <dd>
  1177. <p>The mime type of the file if the browser provided this
  1178. information. An example would be "image/gif".</p>
  1179. </dd>
  1180. </dl>
  1181. <p>The <em><strong>$userfile</strong></em> basename of the above
  1182. variables will match the NAME field in the upload form.</p>
  1183. <p>Files will by default be stored in the server's default
  1184. temporary directory. This can be changed by setting the
  1185. environment variable TMPDIR in the environment in which PHP/FI
  1186. runs. Setting it using a PutEnv() call from within a PHP/FI
  1187. script will not work though. Alternatively, you may hard-code in
  1188. a temporary directory by editing <em>php.h</em> and defining the
  1189. <strong>UPLOAD_TMPDIR</strong> variable.</p>
  1190. <p>The PHP/FI script which receives the uploaded file should
  1191. implement whatever logic is necessary for determining what should
  1192. be done with the uploaded file. You can for example use the
  1193. $file_size variable to throw away any files that are either too
  1194. small or too big. You could use the $file_type variable to throw
  1195. away any files that didn't match a certain type criteria.
  1196. Whatever the logic, you should either delete the file from the
  1197. temporary directory or move it elsewhere.</p>
  1198. <p>Please note that the CERN httpd seems to strip off everything
  1199. starting at the first whitespace in the content-type mime header
  1200. it gets from the client. As long as this is the case, CERN httpd
  1201. will not support the file upload feature.</p>
  1202. <hr />
  1203. <h2><a name="cookies" id="cookies">Cookie Support</a></h2>
  1204. <p>PHP/FI transparently supports HTTP cookies as defined by
  1205. <a href=
  1206. "http://www.netscape.com/newsref/std/cookie_spec.html">Netscape's
  1207. Spec</a>. Cookies are a mechanism for storing data in the remote
  1208. browser and thus tracking or identifying return users. You can
  1209. set cookies using the <a href="#setcookie">SetCookie()</a>
  1210. function. Cookies are part of the HTTP header, so the SetCookie()
  1211. function must be called before any output is sent to the browser.
  1212. This is the same restriction as for the Header() function.</p>
  1213. <p>Any cookies sent to you from the client will automatically be
  1214. turned into a PHP/FI variable just like GET and POST method
  1215. data.</p>
  1216. <p>If you wish to assign multiple values to a single cookie, just
  1217. add <b>[]</b> to the cookie name. For example:</p>
  1218. <pre>
  1219. SetCookie("MyCookie[]","Rasmus Lerdorf", time()+3600);
  1220. </pre>Note that a cookie will replace a previous cookie by the same
  1221. name in your browser unless the path or domain is different. So,
  1222. for a shopping cart application you may want to keep a counter and
  1223. pass this along. ie.
  1224. <pre>
  1225. $Count++;
  1226. SetCookie("Count",$Count, time()+3600);
  1227. SetCookie("Cart[$Count]",$item, time()+3600);
  1228. </pre>
  1229. <hr />
  1230. <h2><a name="msql_support" id="msql_support">mSQL
  1231. Support</a></h2>
  1232. <p>mSQL stands for mini-SQL and is a small and simple SQL
  1233. database engine written by David Hughes. It is available from
  1234. <a href=
  1235. "ftp://ftp.bond.edu.au/pub/Minerva/msql">ftp://ftp.bond.edu.au/pub/Minerva/msql</a></p>
  1236. <p>PHP/FI supports has a rich set of mSQL support functions:</p>
  1237. <dl>
  1238. <dt><a href="#msql">msql()</a></dt>
  1239. <dt><a href="#msql_close">msql_Close()</a></dt>
  1240. <dt><a href="#msql_connect">msql_Connect()</a></dt>
  1241. <dt><a href="#msql_createdb">msql_CreateDB()</a></dt>
  1242. <dt><a href="#msql_dbname">msql_dbName()</a></dt>
  1243. <dt><a href="#msql_dropdb">msql_DropDB()</a></dt>
  1244. <dt><a href="#msql_fieldflags">msql_FieldFlags()</a></dt>
  1245. <dt><a href="#msql_fieldlen">msql_FieldLen()</a></dt>
  1246. <dt><a href="#msql_fieldname">msql_FieldName()</a></dt>
  1247. <dt><a href="#msql_fieldtype">msql_FieldType()</a></dt>
  1248. <dt><a href="#msql_freeresult">msql_FreeResult()</a></dt>
  1249. <dt><a href="#msql_listdbs">msql_ListDBs()</a></dt>
  1250. <dt><a href="#msql_listfields">msql_Listfields()</a></dt>
  1251. <dt><a href="#msql_listtables">msql_ListTables()</a></dt>
  1252. <dt><a href="#msql_numfields">msql_NumFields()</a></dt>
  1253. <dt><a href="#msql_numrows">msql_NumRows()</a></dt>
  1254. <dt><a href="#msql_regcase">msql_RegCase()</a></dt>
  1255. <dt><a href="#msql_result">msql_Result()</a></dt>
  1256. <dt><a href="#msql_tablename">msql_TableName()</a></dt>
  1257. </dl>
  1258. <p>In addition to these functions, PHP/FI can also be compiled to
  1259. automatically escape any forward single quote ( ' ) characters
  1260. found in GET or POST data. If the MAGIC_QUOTES variable is
  1261. defined in the <em>php.h</em> file then these quotes will be
  1262. automatically escaped making it easier to pass form data directly
  1263. to msql queries.</p>
  1264. <hr />
  1265. <h2><a name="pg95_support" id=
  1266. "pg95_support">Postgres95/PostgreSQL Support</a></h2>
  1267. <p>Postgres95/PostgreSQL is a powerful public domain database
  1268. that implements a significant subset of the SQL language. It
  1269. supports many datatypes and commands that are not available in
  1270. mSQL. More information about Postgres and the software itself can
  1271. be found at this URL: <a href=
  1272. "http://www.postgreSQL.org/">http://www.postgreSQL.org/</a>.</p>
  1273. <p>The following PHP functions are available for Postgres95:</p>
  1274. <dl>
  1275. <dt><a href="#pg_connect">pg_Connect()</a></dt>
  1276. <dt><a href="#pg_close">pg_Close()</a></dt>
  1277. <dt><a href="#pg_host">pg_Host()</a></dt>
  1278. <dt><a href="#pg_port">pg_Port()</a></dt>
  1279. <dt><a href="#pg_options">pg_Options()</a></dt>
  1280. <dt><a href="#pg_tty">pg_tty()</a></dt>
  1281. <dt><a href="#pg_dbname">pg_DBname()</a></dt>
  1282. <dt><a href="#pg_exec">pg_Exec()</a></dt>
  1283. <dt><a href="#pg_result">pg_Result()</a></dt>
  1284. <dt><a href="#pg_freeresult">pg_FreeResult()</a></dt>
  1285. <dt><a href="#pg_getlastoid">pg_GetLastOid()</a></dt>
  1286. <dt><a href="#pg_numrows">pg_NumRows()</a></dt>
  1287. <dt><a href="#pg_numfields">pg_NumFields()</a></dt>
  1288. <dt><a href="#pg_fieldnum">pg_FieldNum()</a></dt>
  1289. <dt><a href="#pg_fieldname">pg_FieldName()</a></dt>
  1290. <dt><a href="#pg_fieldtype">pg_FieldType()</a></dt>
  1291. <dt><a href="#pg_fieldsize">pg_FieldSize()</a></dt>
  1292. <dt><a href="#pg_fieldprtlen">pg_FieldPrtLen()</a></dt>
  1293. <dt><a href="#pg_errorMessage">pg_errorMessage()</a></dt>
  1294. </dl>
  1295. <p><strong>Note:</strong> Binary cursors are not supported.</p>
  1296. <p>In addition to these functions, PHP/FI can also be compiled to
  1297. automatically escape any forward single quote ( ' ) and double
  1298. quote ( " ) characters found in GET or POST data. If the
  1299. MAGIC_QUOTES variable is defined in the <em>php.h</em> file then
  1300. these quotes will be automatically escaped making it easier to
  1301. pass form data directly to Postgres queries.</p>
  1302. <p>Here is a sample script that connects to Postgres database on
  1303. localhost called 'mydb' and retrieves the names and ages of
  1304. people in a table:</p>
  1305. <pre>
  1306. &lt;?
  1307. $conn = pg_Connect("localhost", "5432", "", "", "mydb");
  1308. if (!$conn) {
  1309. echo "An error occured.\n";
  1310. exit;
  1311. }
  1312. $result = pg_Exec($conn, "select * from table1");
  1313. if (!$result) {
  1314. echo "An error occured.\n";
  1315. exit;
  1316. }
  1317. $num = pg_NumRows($result);
  1318. $i = 0;
  1319. while ($i &lt; $num) {
  1320. echo "name: ";
  1321. echo pg_Result($result, $i, "name");
  1322. echo " age: ";
  1323. echo pg_Result($result, $i, "age");
  1324. echo "&lt;BR&gt;";
  1325. $i++;
  1326. }
  1327. pg_FreeResult($result);
  1328. pg_Close($conn);
  1329. &gt;
  1330. </pre>
  1331. <hr />
  1332. <h2><a name="mysql_support" id="mysql_support">mysql
  1333. Support</a></h2>
  1334. <p>mysql is an clone of the mSQL package. You can get a copy from
  1335. <a href="http://www.tcx.se/">http://www.tcx.se/</a></p>
  1336. <p>PHP/FI supports has a rich set of mysql support functions:</p>
  1337. <dl>
  1338. <dt><a href="#mysql">mysql()</a></dt>
  1339. <dt><a href="#mysql_close">mysql_Close()</a></dt>
  1340. <dt><a href="#mysql_connect">mysql_Connect()</a></dt>
  1341. <dt><a href="#mysql_createdb">mysql_CreateDB()</a></dt>
  1342. <dt><a href="#mysql_dbname">mysql_dbName()</a></dt>
  1343. <dt><a href="#mysql_dropdb">mysql_DropDB()</a></dt>
  1344. <dt><a href="#mysql_fieldflags">mysql_FieldFlags()</a></dt>
  1345. <dt><a href="#mysql_fieldlen">mysql_FieldLen()</a></dt>
  1346. <dt><a href="#mysql_fieldname">mysql_FieldName()</a></dt>
  1347. <dt><a href="#mysql_fieldtype">mysql_FieldType()</a></dt>
  1348. <dt><a href="#mysql_freeresult">mysql_FreeResult()</a></dt>
  1349. <dt><a href="#mysql_listdbs">mysql_ListDBs()</a></dt>
  1350. <dt><a href="#mysql_listfields">mysql_Listfields()</a></dt>
  1351. <dt><a href="#mysql_listtables">mysql_ListTables()</a></dt>
  1352. <dt><a href="#mysql_numfields">mysql_NumFields()</a></dt>
  1353. <dt><a href="#mysql_numrows">mysql_NumRows()</a></dt>
  1354. <dt><a href="#mysql_result">mysql_Result()</a></dt>
  1355. <dt><a href="#mysql_tablename">mysql_TableName()</a></dt>
  1356. </dl>
  1357. <p>In addition to these functions, PHP/FI can also be compiled to
  1358. automatically escape any forward single quote ( ' ) characters
  1359. found in GET or POST data. If the MAGIC_QUOTES variable is
  1360. defined in the <em>php.h</em> file then these quotes will be
  1361. automatically escaped making it easier to pass form data directly
  1362. to mysql queries.</p>
  1363. <hr />
  1364. <h2><a name="solid_support" id="solid_support">Solid
  1365. Support</a></h2>
  1366. <p>The Solid server is a high-volume SQL server. It supports the
  1367. ANSI SQL2, ODBC, SAG CLI and X/Open SQL standards. More
  1368. information about the Solid server is available at <a href=
  1369. "http://www.solidtech.com/">www.solidtech.com</a>. The Solid
  1370. interface to PHP was developed by <a href=
  1371. "http://solid.digiface.nl/">DigiFace Internet Services</a>.</p>
  1372. <p>The following PHP functions are available for the Solid
  1373. Server:</p>
  1374. <dl>
  1375. <dt><a href="#solid_connect">Solid_Connect()</a></dt>
  1376. <dt><a href="#solid_close">Solid_Close()</a></dt>
  1377. <dt><a href="#solid_exec">Solid_Exec()</a></dt>
  1378. <dt><a href="#solid_result">Solid_Result()</a></dt>
  1379. <dt><a href="#solid_freeresult">Solid_FreeResult()</a></dt>
  1380. <dt><a href="#solid_numrows">Solid_NumRows()</a></dt>
  1381. <dt><a href="#solid_numfields">Solid_NumFields()</a></dt>
  1382. <dt><a href="#solid_fieldnum">Solid_FieldNum()</a></dt>
  1383. <dt><a href="#solid_fieldname">Solid_FieldName()</a></dt>
  1384. </dl>
  1385. <p>In addition to these functions, PHP/FI can also be compiled to
  1386. automatically escape any forward single quote ( ' ) characters
  1387. found in GET or POST data. If the MAGIC_QUOTES variable is
  1388. defined in the <em>php.h</em> file then these quotes will be
  1389. automatically escaped making it easier to pass form data directly
  1390. to Solid queries.</p>
  1391. <p>Here is the same script that was shown in the Postgres
  1392. section, adapted for the Solid server.</p>
  1393. <pre>
  1394. &lt;?
  1395. $conn = Solid_Connect("", "username", "password");
  1396. if (!$conn) {
  1397. echo "An error occured.\n";
  1398. exit;
  1399. }
  1400. $result = Solid_Exec($conn, "select * from table1");
  1401. if (!$result) {
  1402. echo "An error occured.\n";
  1403. exit;
  1404. }
  1405. while (Solid_FetchRow($result)) {
  1406. echo "name: ";
  1407. echo Solid_Result($result, "name");
  1408. echo " age: ";
  1409. echo Solid_Result($result, "age");
  1410. echo "&lt;BR&gt;";
  1411. }
  1412. Solid_FreeResult($result);
  1413. Solid_Close($conn);
  1414. &gt;
  1415. </pre>
  1416. <hr />
  1417. <h2><a name="sybase_support" id="sybase_support">Sybase
  1418. Support</a></h2>The supporting functions uses Sybase DB library
  1419. API calls. Therefore you must have sybase API libraries and
  1420. headers files installed in your system in order to compile PHP/FI
  1421. with sybase support.
  1422. <p>The following PHP/FI functions are available for Sybase.</p>
  1423. <dl>
  1424. <dt><a href=
  1425. "#sybsql_checkconnect">SybSQL_CheckConnect()</a></dt>
  1426. <dt><a href="#sybsql_connect">SybSQL_Connect()</a></dt>
  1427. <dt><a href="#sybsql_DBuse">SybSQL_DBuse()</a></dt>
  1428. <dt><a href="#sybsql_Exit">SybSQL_Exit()</a></dt>
  1429. <dt><a href="#sybsql_fieldname">SybSQL_Fieldname()</a></dt>
  1430. <dt><a href="#sybsql_getfield">SybSQL_GetField()</a></dt>
  1431. <dt><a href="#sybsql_isrow">SybSQL_IsRow()</a></dt>
  1432. <dt><a href="#sybsql_nextrow">SybSQL_NextRow()</a></dt>
  1433. <dt><a href="#sybsql_numfields">SybSQL_NumFields()</a></dt>
  1434. <dt><a href="#sybsql_numrows">SybSQL_NumRows()</a></dt>
  1435. <dt><a href="#sybsql_query">SybSQL_Query()</a></dt>
  1436. <dt><a href="#sybsql_result">SybSQL_Result()</a></dt>
  1437. <dt><a href="#sybsql_result_all">SybSQL_Result_All()</a></dt>
  1438. <dt><a href="#sybsql_seek">SybSQL_Seek()</a></dt>
  1439. </dl>
  1440. <p>For a complete example, see the example following the <a href=
  1441. "#sybsql_result">sybSQL_Result()</a> function.</p>
  1442. <hr />
  1443. <h2><a name="oracle_support" id="oracle_support">Oracle
  1444. Support</a></h2>The PHP/FI interface to Oracle uses the Oracle
  1445. Call Interface (OCI). You need the OCI libraries on your system
  1446. to compile PHP/FI with Oracle support.
  1447. <p>The following PHP/FI functions are available for Oracle:</p>
  1448. <dl>
  1449. <dt><a href="#ora_bind">Ora_Bind()</a></dt>
  1450. <dt><a href="#ora_close">Ora_Close()</a></dt>
  1451. <dt><a href="#ora_commit">Ora_Commit()</a></dt>
  1452. <dt><a href="#ora_commitoff">Ora_CommitOff()</a></dt>
  1453. <dt><a href="#ora_commiton">Ora_CommitOn()</a></dt>
  1454. <dt><a href="#ora_exec">Ora_Exec()</a></dt>
  1455. <dt><a href="#ora_fetch">Ora_Fetch()</a></dt>
  1456. <dt><a href="#ora_getcolumn">Ora_GetColumn()</a></dt>
  1457. <dt><a href="#ora_logoff">Ora_Logoff()</a></dt>
  1458. <dt><a href="#ora_logon">Ora_Logon()</a></dt>
  1459. <dt><a href="#ora_open">Ora_Open()</a></dt>
  1460. <dt><a href="#ora_parse">Ora_Parse()</a></dt>
  1461. <dt><a href="#ora_rollback">Ora_Rollback()</a></dt>
  1462. </dl>
  1463. <p>An example PHP/FI Oracle application:</p>
  1464. <pre>
  1465. &lt;?
  1466. PutEnv("ORACLE_HOME=path_to_your_oracle_home"
  1467. PutEnv("ORACLE_SID=database"
  1468. /* Establish a connection between PHP and Oracle. */
  1469. $conn = Ora_Logon("username" "password"
  1470. if ($conn &lt; 0) {
  1471. echo("Could not connect to Oracle.\n"
  1472. exit;
  1473. }
  1474. /* Open a cursor in Oracle. */
  1475. $cursor = Ora_Open($conn);
  1476. if ($cursor &lt; 0) {
  1477. echo("Could not open a cursor.\n"
  1478. Ora_Logoff($conn);
  1479. exit;
  1480. }
  1481. /* Turn off autocommit. */
  1482. Ora_CommitOff($conn);
  1483. /* This is the SQL query. */
  1484. $query = "SELECT * FROM some_table"
  1485. if (Ora_Parse($cursor, $query) &lt; 0) {
  1486. echo("Parse failed!\n"
  1487. Ora_Logoff($conn);
  1488. exit;
  1489. }
  1490. /* Execute the SQL statement associated with $cursor and
  1491. prepare storage for select-list items. */
  1492. $ncols = Ora_Exec($cursor);
  1493. echo "lt;P&gt;\n"
  1494. echo "lt;TABLE BORDER=1 CELLSPACING=0&gt;\n"
  1495. /* Retrieve all rows from the database one after another. */
  1496. while (Ora_Fetch($cursor) == 1) {
  1497. $i = 0;
  1498. echo "lt;TR&gt;\n"
  1499. while ($i &lt; $ncols) {
  1500. /* Get data for a single column of currently fetched row. */
  1501. $col = Ora_GetColumn($cursor, $i);
  1502. echo("lt;TD&gt;$col&lt;/TD&gt;\n"
  1503. $i++;
  1504. }
  1505. echo("lt;/TR&gt;\n"
  1506. }
  1507. echo "&lt;/TABLE&gt;\n";
  1508. /* Close the Oracle connection. */
  1509. Ora_Close($cursor);
  1510. /* Disconnect the logon data area. */
  1511. Ora_Logoff($conn);
  1512. &gt;
  1513. </pre>
  1514. <hr />
  1515. <h2><a name="illustra_support" id="illustra_support">Informix
  1516. Illustra Support</a></h2>
  1517. <p>Illustra is a commercial database sold by Informix. It has
  1518. several features that are not fully supported by this interface
  1519. (yet). The main claim to fame for Illustra is that it is an
  1520. object-relational database capable of being extended in an
  1521. object-orientated fashion. For example, it is possible to have an
  1522. Image as a base type within the database. More information can be
  1523. obtained from <a href="http://www.illustra.com/">The illustra
  1524. home page</a>.</p>
  1525. <p>The following PHP functions are available for Illustra:</p>
  1526. <dl>
  1527. <dt><a href="#mi_connect">mi_Connect()</a></dt>
  1528. <dt><a href="#mi_close">mi_Close()</a></dt>
  1529. <dt><a href="#mi_dbname">mi_DBname()</a></dt>
  1530. <dt><a href="#mi_exec">mi_Exec()</a></dt>
  1531. <dt><a href="#mi_result">mi_Result()</a></dt>
  1532. <dt><a href="#mi_numrows">mi_NumRows()</a></dt>
  1533. <dt><a href="#mi_numfields">mi_NumFields()</a></dt>
  1534. <dt><a href="#mi_fieldnum">mi_FieldNum()</a></dt>
  1535. <dt><a href="#mi_fieldname">mi_FieldName()</a></dt>
  1536. </dl>
  1537. <p><strong>Note:</strong> Type operations are not yet
  1538. supported.</p>
  1539. <p>Here is a sample script that connects to the illustra database
  1540. on localhost called 'mydb' and retrieves the names and ages of
  1541. people in a table:</p>
  1542. <pre>
  1543. &lt;?
  1544. $conn = mi_Connect("mydb", "username", "password");
  1545. if ($conn&lt;0) {
  1546. echo "An error occured on connection.\n";
  1547. exit;
  1548. }
  1549. $result = mi_Exec($conn, "select * from table1");
  1550. if ($result &lt; 0) {
  1551. echo "An error occured.\n";
  1552. exit;
  1553. }
  1554. $num = mi_NumRows($result);
  1555. $i = 0;
  1556. while ($i &lt; $num) {
  1557. echo "name: ";
  1558. echo mi_Result($result, $i, "name");
  1559. echo " age: ";
  1560. echo mi_Result($result, $i, "age");
  1561. echo "&lt;BR&gt;";
  1562. $i++;
  1563. }
  1564. mi_Close($conn);
  1565. &gt;
  1566. </pre>
  1567. <hr />
  1568. <h2><a name="adabas_support" id="adabas_support">Adabas
  1569. Support</a></h2>
  1570. <p>Adabas D is an advanced RDBMS that is available on many
  1571. platforms. A special version, the so called Personal Edition is
  1572. available for Linux and Win32 at no cost. It is resticted to 5
  1573. simulataneous users and 100 MB of data. For more information on
  1574. Adabas D refer to <a href=
  1575. "http://www.softwareag.com">http://www.softwareag.com</a>.</p>
  1576. <p>The following PHP functions are available for accessing Adabas
  1577. databases:</p>
  1578. <dl>
  1579. <dt><a href="#ada_connect">Ada_Connect()</a></dt>
  1580. <dt><a href="#ada_close">Ada_Close()</a></dt>
  1581. <dt><a href="#ada_exec">Ada_Exec()</a></dt>
  1582. <dt><a href="#ada_result">Ada_Result()</a></dt>
  1583. <dt><a href="#ada_resultall">Ada_ResultAll()</a></dt>
  1584. <dt><a href="#ada_freeresult">Ada_FreeResult()</a></dt>
  1585. <dt><a href="#ada_numrows">Ada_NumRows()</a></dt>
  1586. <dt><a href="#ada_numfields">Ada_NumFields()</a></dt>
  1587. <dt><a href="#ada_numrows">Ada_NumRows()</a></dt>
  1588. <dt><a href="#ada_numfields">Ada_NumFields()</a></dt>
  1589. <dt><a href="#ada_fieldnum">Ada_FieldNum()</a></dt>
  1590. <dt><a href="#ada_fieldname">Ada_FieldName()</a></dt>
  1591. <dt><a href="#ada_fieldtype">Ada_FieldType()</a></dt>
  1592. </dl>Here is the same script that was shown in the Postgres and
  1593. Solid sections, adapted for Adabas D.
  1594. <pre>
  1595. &lt;?
  1596. $conn = Ada_Connect("node:db", "username", "password");
  1597. if (!$conn) {
  1598. echo "An error occured.\n";
  1599. exit;
  1600. }
  1601. $result = Ada_Exec($conn, "select * from table1");
  1602. if (!$result) {
  1603. echo "An error occured.\n";
  1604. exit;
  1605. }
  1606. while (Ada_FetchRow($result)) {
  1607. echo "name: ";
  1608. echo Ada_Result($result, "name");
  1609. echo " age: ";
  1610. echo Ada_Result($result, "age");
  1611. echo "&lt;BR&gt;";
  1612. }
  1613. Ada_FreeResult($result);
  1614. Ada_Close($conn);
  1615. &gt;
  1616. </pre>
  1617. <hr />
  1618. <h2><a name="regexp" id="regexp">Regular Expressions</a></h2>
  1619. <p>Regular expressions are used for complex string manipulation
  1620. in PHP/FI. The script interface to the regular expression support
  1621. is through the following functions: <a href="#ereg">EReg()</a>,
  1622. <a href="#eregi">ERegi()</a>, <a href=
  1623. "#ereg_replace">EReg_Replace()</a>, <a href=
  1624. "#eregi_replace">ERegi_Replace()</a>, <a href=
  1625. "#reg_match">Reg_Match()</a>, <a href=
  1626. "#reg_replace">Reg_Replace()</a>, and <a href=
  1627. "#reg_search">Reg_Search()</a>. The first argument to all three
  1628. functions is a regular expression string. The EReg functions use
  1629. the Posix Extended regular expressions as defined by POSIX
  1630. 1003.2, while the Reg functions implement Basic regular
  1631. expressions. For a complete description of regular expressions
  1632. see your regex(7) man page. If you do not have this page, the
  1633. regex(7) man page written by Henry Spencer can be found in the
  1634. src/regex directory in the PHP/FI distribution. Ask your system
  1635. administrator to install this man page for you.</p>
  1636. <p>Some examples of regular expressions and what they do:</p>
  1637. <blockquote>
  1638. <dl>
  1639. <dt><tt>ereg("abc",$string);</tt></dt>
  1640. <dd>Returns true if "abc" is found anywhere in $string.</dd>
  1641. <dt><tt>ereg("^abc",$string);</tt></dt>
  1642. <dd>Returns true if "abc" is found at the beginning of
  1643. $string.</dd>
  1644. <dt><tt>ereg("abc$",$string);</tt></dt>
  1645. <dd>Returns true if "abc" is found at the end of
  1646. $string.</dd>
  1647. <dt>
  1648. <tt>eregi("(ozilla.[23]|MSIE.3)",$HTTP_USER_AGENT);</tt></dt>
  1649. <dd>Returns true if client browser is Netscape 2, 3 or MSIE
  1650. 3.</dd>
  1651. <dt><tt>ereg("([[:alnum:]]+) ([[:alnum:]]+)
  1652. ([[:alnum:]]+)",$string,$regs);</tt><br /></dt>
  1653. <dd>Places three space separated words into $regs[1],
  1654. $regs[2] and $regs[3].</dd>
  1655. <dt><tt>ereg_replace("^","&lt;BR&gt;",$string)</tt></dt>
  1656. <dd>Put a &lt;BR&gt; tag at the beginning of $string.</dd>
  1657. <dt><tt>ereg_replace("$","&lt;BR&gt;",$string)</tt></dt>
  1658. <dd>Put a &lt;BR&gt; tag at the end of $string.</dd>
  1659. <dt><tt>ereg_replace(10,"",$string);</tt></dt>
  1660. <dd>Get rid of any linefeed characters in $string.</dd>
  1661. <dt><tt>ereg_replace(13,"&lt;BR&gt;",$string);</tt></dt>
  1662. <dd>Replace all carriage returns with a &lt;BR&gt; tag in
  1663. $string.</dd>
  1664. </dl>
  1665. </blockquote>
  1666. <hr />
  1667. <h2><a name="escapes" id="escapes">Escape Characters</a></h2>
  1668. <p>The following escape sequences are supported in most places
  1669. where a quoted string argument is used:</p>
  1670. <blockquote>
  1671. <pre>
  1672. \a --&gt; bell
  1673. \b --&gt; backspace
  1674. \n --&gt; linefeed
  1675. \r --&gt; carriage return
  1676. \t --&gt; tab
  1677. \nnn --&gt; octal char
  1678. \xXX --&gt; hex char
  1679. </pre>
  1680. </blockquote>
  1681. <hr />
  1682. <h2><a name="octal" id="octal">Octal Notation of Unix file
  1683. permissions</a></h2>
  1684. <p>A couple of functions in the PHP/FI script language epxect
  1685. octal arguments to denote Unix-style permission parameters. In
  1686. this octal notation 3 bits are used to represent the values 0-7.
  1687. Each bit of the three represents a specific permission. Octal is
  1688. traditionally noted in some contexts by a leading 0, such as
  1689. 0755. You do not need to use this leading 0 in PHP since the
  1690. functions that expect octal parameters are will simplyassume that
  1691. the parameter is octal. Using the leading 0 is however good
  1692. practise to remind yourself that you are no longer dealing with a
  1693. base 10 value.</p>
  1694. <p><b>Bit Description</b></p>
  1695. <pre>
  1696. xxx
  1697. ^^^
  1698. ||+----1 bit (execute permission)
  1699. |+-----2 bit (write permission)
  1700. +------4 bit (read permission)
  1701. </pre>These three bits are repeated three times for owner, group,
  1702. and world. Thus 0755 means:
  1703. <pre>
  1704. owner: r,w,x
  1705. group: r, ,x
  1706. world: r, ,x
  1707. </pre>Note that the execute bit on a directory means 'access', not
  1708. 'execute'. There are also the extended bits in the fourth octal
  1709. nibble, like 0?755:
  1710. <pre>
  1711. 4: suid bit (set userid)
  1712. 2: sgid bit (set group id)
  1713. 1: sticky bit (on a directory, only the owner can delete a file)
  1714. </pre>
  1715. <hr />
  1716. <h2><a name="script" id="script">PHP/FI Script Language</a></h2>
  1717. <p>The PHP script language is similar in syntax to the C language
  1718. in many ways. It supports variables, arrays, function calls,
  1719. different variable types and most things you might need to write
  1720. complex cgi programs.</p>
  1721. <p>Each PHP/FI function is described in the following section and
  1722. can be quickly found by simply appending #function_name to the
  1723. url for this document since each function description has been
  1724. tagged with its name.</p>
  1725. <h3><a name="syntax" id="syntax">Syntax</a></h3>
  1726. <p>Each PHP instruction starts with <strong>&lt;?</strong> and
  1727. ends with a <strong>&gt;</strong>. Or, instructions may be
  1728. grouped inside a single <strong>&lt;? &gt;</strong> pair and
  1729. separated by <strong>;</strong> characters.</p>
  1730. <p>Variables are supported and are indicated by preceding the
  1731. variable name with a <strong>$</strong>. So, for example, to set
  1732. a variable to 5 and then display this variable, the following is
  1733. valid:</p>
  1734. <pre>
  1735. &lt;?$a = 5&gt;
  1736. &lt;?echo $a&gt;
  1737. </pre>
  1738. <p>This is the same as writing:</p>
  1739. <pre>
  1740. &lt;? $a = 5; echo $a &gt;
  1741. </pre>
  1742. <p>Or even:</p>
  1743. <pre>
  1744. &lt;?
  1745. $a = 5;
  1746. echo $a;
  1747. &gt;
  1748. </pre>
  1749. <p>Extra white space characters such as spaces, tabs and
  1750. new-lines are ignored. This fact should be used to format the PHP
  1751. script blocks to make them easier to read. Case is relevant in
  1752. variable names, but not in function calls. In the functional
  1753. overview later on in this documentation, case is only used to
  1754. make the function names easier to read. In the actual script
  1755. language you can use any case you wish.</p>
  1756. <p>Comments are supported. A comment is written just like
  1757. comments in the C language. <strong>/*</strong> starts a comment
  1758. and <strong>*/</strong> ends a comment. Comments can be placed
  1759. anywhere within the <strong>&lt;? ... &gt;</strong> block.</p>
  1760. <hr />
  1761. <h3><a name="vars" id="vars">Variables</a></h3>
  1762. <p>Three types of variables are supported. <strong>Long
  1763. integer</strong>, <strong>Double precision floating
  1764. point</strong> and <strong>character strings</strong>. They are
  1765. automatically detected. For example:</p>
  1766. <pre>
  1767. &lt;?$a = 5&gt;
  1768. </pre>
  1769. <p>causes $a to become a variable of type INTEGER.</p>
  1770. <pre>
  1771. &lt;?$a = 5.0&gt;
  1772. </pre>
  1773. <p>causes $a to become a variable of type DOUBLE.</p>
  1774. <pre>
  1775. &lt;?$a = "5"&gt;
  1776. </pre>
  1777. <p>causes $a to become a variable of type STRING.</p>
  1778. <p>The type of the variable is not generally important. Every
  1779. variable regardless of its type is converted to all three types
  1780. internally and the various functions will try to use the correct
  1781. type. There are only a few functions affected by the type of the
  1782. variable.</p>
  1783. <p>All three variable types may also be treated as arrays by
  1784. appending <strong>[value]</strong> to their names. Unlike C,
  1785. these are actually associative arrays similar to those used in
  1786. Perl. The following would be valid:</p>
  1787. <pre>
  1788. &lt;?
  1789. $a[0] = 5;
  1790. $a["hello"] = 6;
  1791. echo $a[0];
  1792. echo $a["hello"];
  1793. &gt;
  1794. </pre>
  1795. <p>Note that if a variable is used both as an array and as a
  1796. normal variable, the normal variable is synonymous with the index
  1797. "0" entry in the array. ie.</p>
  1798. <pre>
  1799. $a = 1;
  1800. </pre>
  1801. <p>Is the same as writing:</p>
  1802. <pre>
  1803. $a[0] = 1;
  1804. </pre>
  1805. <p>PHP/FI also supports non-indexed arrays. A non-indexed array
  1806. will generate its own index as items are added to it. For
  1807. example:</p>
  1808. <pre>
  1809. $a[] = "Hello";
  1810. $a[] = "There";
  1811. </pre>
  1812. <p>The first item inserted into a non-indexed array always gets
  1813. assigned index 0, the second index 1, etc. Therefore the above
  1814. items may be printed out with:</p>
  1815. <pre>
  1816. echo $a[0];
  1817. echo $a[1];
  1818. </pre>
  1819. <p>Arrays can be copied by a simple assignment. If $b is an
  1820. array, then all the values can be copied to a new array named $a
  1821. with:</p>
  1822. <pre>
  1823. $a = $b;
  1824. </pre>
  1825. <p>Please not that if PHP does not force you to define variables
  1826. before using them. If in the above statement, $b was undefined,
  1827. then $a would be set to an empty string ("").</p>
  1828. <p>The [] notation is also used to indicate that arrays are to be
  1829. appended. If $a and $b are both arrays, then $b can be appended
  1830. to $a by:</p>
  1831. <pre>
  1832. $a[] = $b;
  1833. </pre>
  1834. <p>In the above, there will be a difference between associative
  1835. arrays and normal numbered arrays. Numbered arrays will be
  1836. renumbered such that all elements from $b will come after the
  1837. original elements from $a. While with associative arrays,
  1838. elements in $b will be merged with elements in $a. Any elements
  1839. (items with the same index name) which already exist in $a will
  1840. be overwritten by $b elements.</p>
  1841. <p>You can use the <a href="#count">count()</a> function to
  1842. determine the number of items in any array.</p>
  1843. <p>Also inherent to the language is the fact that the type of the
  1844. variable determines how certain basic operations will be carried
  1845. out. For example:</p>
  1846. <pre>
  1847. $a = $b + $c;
  1848. </pre>
  1849. <p>can do a couple of different things. If $b is a number, the
  1850. numerical value of $c is added to $b and the sum is stored in $a.
  1851. In this case the type of $c is irrelevant. The operation is
  1852. guided by the type of the first variable. If $b is a string, then
  1853. the string value of $c is appended to $b and the resultant string
  1854. is placed in $a. This also leads to some caveats. You should read
  1855. the section on <a href="#overload">overloaded operators</a> to
  1856. get a better understanding of how to deal with them.</p>
  1857. <hr />
  1858. <h3><a name="assoc" id="assoc">Associative Arrays</a></h3>
  1859. <p>The previous section introduced associative arrays. An
  1860. associative array is an array in which the index need not be a
  1861. numerically sequential value. The array index can be any number
  1862. or string. PHP/FI provides a set of functions to manipulate these
  1863. associative arrays. These include, <a href="#next">Next()</a>,
  1864. <a href="#prev">Prev()</a>,<a href="#reset">Reset()</a>,<a href=
  1865. "#end">End()</a>, and <a href="#key">Key()</a>.</p>
  1866. <hr />
  1867. <h3><a name="varvars" id="varvars">Variable Variables</a></h3>
  1868. <p>Sometimes it is convenient to be able to have variable
  1869. variable names. That is, a variable name which can be set and
  1870. used dynamically. A normal variable is set with a statement such
  1871. as:</p>
  1872. <pre>
  1873. $a = "hello";
  1874. </pre>
  1875. <p>A variable variable takes the value of a variable and treats
  1876. that as the name of a variable. In the above example,
  1877. <strong>hello</strong>, can be used as the name of a variable by
  1878. using two dollar signs. ie.</p>
  1879. <pre>
  1880. $$a = "world";
  1881. </pre>
  1882. <p>At this point two variables have been defined and stored in
  1883. the PHP/FI symbol tree:</p>
  1884. <pre>
  1885. Variable Name Variable Content
  1886. <em>a</em> <em>hello</em>
  1887. <em>hello</em> <em>world</em>
  1888. </pre>
  1889. <p>Therefore, this statement:</p>
  1890. <pre>
  1891. echo "$a $$a";
  1892. </pre>
  1893. <p>produces the exact same output as:</p>
  1894. <pre>
  1895. echo "$a $hello";
  1896. </pre>
  1897. <p>ie. they both produce: <strong>hello world</strong></p>
  1898. <hr />
  1899. <h3><a name="lang" id="lang">Language Constructs</a></h3>
  1900. <p>As far as language constructs are concerned, the PHP language
  1901. is quite simple. The following commands are used to guide the
  1902. control flow through a file:</p>
  1903. <ul>
  1904. <li>if (condition)</li>
  1905. <li>else</li>
  1906. <li>elseif (condition)</li>
  1907. <li>endif</li>
  1908. <li>switch(expression)</li>
  1909. <li>case expression</li>
  1910. <li>default</li>
  1911. <li>break</li>
  1912. <li>endswitch</li>
  1913. <li>while</li>
  1914. <li>endwhile</li>
  1915. <li>include</li>
  1916. <li>exit</li>
  1917. </ul>
  1918. <p>The syntax of conditions are similar to that of the C
  1919. language. <strong>==</strong> tests for equality.
  1920. <strong>!=</strong> means not equal. Also supported are:
  1921. <strong>&gt;</strong>, <strong>&lt;</strong>,
  1922. <strong>&gt;=</strong>, <strong>&lt;=</strong>. Conditional AND
  1923. is <strong>&amp;&amp;</strong>, conditional OR is
  1924. <strong>||</strong>.</p>
  1925. <p>Examples:</p>
  1926. <pre>
  1927. &lt;?
  1928. if($a==5 &amp;&amp; $b!=0 );
  1929. $c = 100 + $a / $b;
  1930. endif;
  1931. &gt;
  1932. </pre>
  1933. <p>The above may also be written in standard C syntax:<br />
  1934. In this case, there is no need for a semicolon after the closing
  1935. curly brace.</p>
  1936. <pre>
  1937. &lt;?
  1938. if($a==5 &amp;&amp; $b!=0) {
  1939. $c = 100 + $a / $b;
  1940. }
  1941. &gt;
  1942. </pre>
  1943. <p>There is no difference between the two syntaxes. I personally
  1944. like to use endif, endswitch and endwhile so I explicitly know
  1945. which construct I am ending. However, these ending constructs can
  1946. always be replaced with a closing curly brace.</p>
  1947. <p>It is important to note that the flow of the language is not
  1948. dependent on the organization of the script blocks within the
  1949. code. You can start an if expression in one block and have the
  1950. end of the expression in another. For example:</p>
  1951. <pre>
  1952. &lt;?if($a==5 &amp;&amp; $b!=0)&gt;
  1953. &lt;b&gt;Normal html text&lt;/b&gt;
  1954. &lt;?endif&gt;
  1955. </pre>
  1956. <p>In this example it is easy to see why it is sometimes more
  1957. desirable to use the <tt>endif</tt> keyword as opposed to a
  1958. closing brace. The above is much more readable than the
  1959. following:</p>
  1960. <pre>
  1961. &lt;?if($a==5 &amp;&amp; $b!=0) {&gt;
  1962. &lt;b&gt;Normal html text&lt;/b&gt;
  1963. &lt;? } &gt;
  1964. </pre>
  1965. <p>Both version are valid and they will do exactly the same
  1966. thing.</p>
  1967. <hr />
  1968. <h3><a name="user_funcs" id="user_funcs">User-Defined
  1969. Functions</a></h3>
  1970. <p>You may define a function within a PHP script with the
  1971. following syntax:</p>
  1972. <pre>
  1973. &lt;?
  1974. Function Test (
  1975. echo "This is a test\n";
  1976. );
  1977. &gt;
  1978. </pre>
  1979. <p>This function can now be called from anywhere in the script as
  1980. long as the call comes after the function definition. A sample
  1981. call might be:</p>
  1982. <pre>
  1983. &lt;?
  1984. Test();
  1985. &gt;
  1986. </pre>
  1987. <p>User defined functions like this act exactly like PHP's
  1988. internal functions in that you can pass arguments to them and
  1989. have them return a value. Here is the syntax for a function
  1990. definition of a function which takes 3 arguments and returns the
  1991. sum of these arguments:</p>
  1992. <pre>
  1993. &lt;?
  1994. Function Sum $a,$b,$c (
  1995. return($a+$b+$c);
  1996. );
  1997. echo Sum($a,$b,$c);
  1998. &gt;
  1999. </pre>
  2000. <p>The <em>return</em> statement is used to return a value from
  2001. the function. Only a single value can be returned using this
  2002. mechanism, however, if more values need to be communicated back
  2003. and forth between the main code and functions, global variables
  2004. can be used. This brings us to the section on the scope of
  2005. variables.</p>
  2006. <hr />
  2007. <h3><a name="scope" id="scope">Scope of Variables</a></h3>
  2008. <p>The scope of a variable is the context within which it is
  2009. defined. For the most part all PHP/FI variables only have a
  2010. single scope. However, within user-defined functions a local
  2011. function scope is introduced. Any variable used inside a function
  2012. is by default limited to the local function scope. For
  2013. example:</p>
  2014. <pre>
  2015. $a=1; /* global scope */
  2016. Function Test (
  2017. echo $a; /* reference to local scope variable */
  2018. );
  2019. Test();
  2020. </pre>
  2021. <p>This script will not produce any output because the
  2022. <em>echo</em> statement refers to a local version of the
  2023. <em>$a</em> variable, and it has not been assigned a value within
  2024. this scope. You may notice that this is a little bit different
  2025. from the C language in that global variables in C are
  2026. automatically available to functions unless specifically
  2027. overridden by a local definition. This can cause some problems in
  2028. that people may inadvertently change a global variable. In PHP/FI
  2029. global variables must be declared global inside a function if
  2030. they are going to be used in that function. An example:</p>
  2031. <pre>
  2032. $a=1;
  2033. $b=2;
  2034. Function Sum $first,$second (
  2035. global $a,$b;
  2036. $b = $a + $b;
  2037. );
  2038. Sum();
  2039. echo $b;
  2040. </pre>
  2041. <p>The above script will output "3". By declaring $a and $b
  2042. global within the function, all references to either variable
  2043. will refer to the global version. There is no limit to the number
  2044. of global variables that can be manipulated by a function.
  2045. However, the variable must exist in the global scope prior to the
  2046. function being called. You cannot create new global variables
  2047. from within a function.</p>
  2048. <p>Another important feature of variable scoping is the
  2049. <em>static</em> variable. A static variable exists only in a
  2050. local function scope, but it does not lose its value when program
  2051. execution leaves this scope. Consider the following example:</p>
  2052. <pre>
  2053. Function Test (
  2054. $a=0;
  2055. echo $a;
  2056. $a++;
  2057. );
  2058. </pre>
  2059. <p>This function is quite useless since every time it is called
  2060. it sets $a to 0 and prints "0". The $a++ which increments the
  2061. variable serves no purpose since as soon as the function exits
  2062. the $a variable disappears. To make a useful counting function
  2063. which will not lose track of the current count, the $a variable
  2064. is declared static:</p>
  2065. <pre>
  2066. Function Test (
  2067. static $a=0;
  2068. echo $a;
  2069. $a++;
  2070. );
  2071. </pre>
  2072. <p>Now, every time the Test() function is called it will print
  2073. the value of $a and increment it.</p>
  2074. <p>Static variables are also essential when functions are called
  2075. recursively. A recursive function is one which calls itself. Care
  2076. must be taken when writing a recursive function because it is
  2077. possible to make it recurse indefinitely. You must make sure you
  2078. have an adequate way of terminating the recursion. The following
  2079. simple function recursively counts to 10:</p>
  2080. <pre>
  2081. Function Test (
  2082. static $count=0;
  2083. $count++;
  2084. echo $count;
  2085. if($count &lt; 10) {
  2086. Test();
  2087. }
  2088. );
  2089. </pre>
  2090. <hr />
  2091. <h3><a name="math" id="math">Mathematical Expressions</a></h3>
  2092. <p>PHP supports full mathematical operations anywhere an
  2093. expression is expected. Order of operations are taken into
  2094. account. The following are the valid operators:</p>
  2095. <pre>
  2096. &lt;? $a = 2 + 1 &gt; <em>Addition</em>
  2097. &lt;? $a = 2 - 1 &gt; <em>Subtraction</em>
  2098. &lt;? $a = 2 * 1 &gt; <em>Multiplication</em>
  2099. &lt;? $a = 2 / 1 &gt; <em>Division</em>
  2100. &lt;? $a = 2 % 1 &gt; <em>Modulus</em>
  2101. &lt;? $a = 2 ^ 1 &gt; <em>Bit-wise Exclusive OR</em>
  2102. </pre>
  2103. <p>Both bracketing and order of operations is supported, so the
  2104. following is valid:</p>
  2105. <pre>
  2106. &lt;?$a = (2+1)*3+6/3&gt;
  2107. </pre>
  2108. <p>The C-like incremental operators <tt>+=</tt> and <tt>-=</tt>
  2109. are supported. ie.</p>
  2110. <pre>
  2111. &lt;? $a += $b&gt;
  2112. </pre>
  2113. <p>This is equivalent to:</p>
  2114. <pre>
  2115. &lt;? $a = $a + $b&gt;
  2116. </pre>
  2117. <p>The C-like bit-wise operators <tt>&amp;=</tt>, <tt>|=</tt> and
  2118. <tt>^=</tt> are supported. ie.</p>
  2119. <pre>
  2120. &lt;? $a &amp;= 4&gt;
  2121. </pre>This is equivalent to:
  2122. <pre>
  2123. &lt;? $a = $a &amp; 4&gt;
  2124. </pre>
  2125. <hr />
  2126. <h3><a name="while" id="while">While Loops</a></h3>
  2127. <p>You can loop within a PHP script by using the <em>while();
  2128. endwhile;</em> construct.</p>
  2129. <pre>
  2130. &lt;?
  2131. $a=0;
  2132. while($a&lt;100) {
  2133. $a++;
  2134. echo $list[$a];
  2135. }
  2136. &gt;
  2137. </pre>
  2138. <p>The above example shows the use of a while loop to display the
  2139. contents of an array. <strong>WARNING</strong> although the PHP
  2140. language supports incremental operators such as
  2141. <strong>++</strong> and <strong>-&lt;!&gt;-</strong> to increment
  2142. and decrement a variable, they are not treated exactly like they
  2143. would be in the C language. The variable is incremented right
  2144. away. There is no concept of incrementing the variable before or
  2145. after the operation as there is in C.</p>
  2146. <p>As explained in the <a href="#lang">Language Constructs</a>
  2147. section above, the same can be obtained with <em>while();
  2148. endwhile;</em>.</p>
  2149. <hr />
  2150. <h3><a name="switch" id="switch">Switch Construct</a></h3>
  2151. <p>PHP supports a switch construct very similar to the C
  2152. equivalent.</p>
  2153. <pre>
  2154. &lt;?
  2155. $a=0;
  2156. switch($a) {
  2157. case 1;
  2158. echo "a is 1";
  2159. break;
  2160. case "hello";
  2161. echo "a is hello";
  2162. break;
  2163. default;
  2164. echo "a is unknown";
  2165. break;
  2166. }
  2167. &gt;
  2168. </pre>
  2169. <p>The above is an example of a switch construct. It is similar
  2170. to a series of if/elseif/else constructs but easier to read. The
  2171. only difference between the PHP switch construct and that of the
  2172. C language is that semi-colons are used to terminate every line.
  2173. There are no colons.</p>
  2174. <p>As explained in the <a href="#lang">Language Constructs</a>
  2175. section above, the same can be obtained with <em>switch();
  2176. endswitch;</em>.</p>
  2177. <p>All of these constructs can of course be nested and used
  2178. inside each other just like C. The various files in the
  2179. <em>examples</em> directory of the PHP distribution should
  2180. provide a good starting point for learning the language.</p>
  2181. <hr />
  2182. <h3><a name="secure" id="secure">Secure Variables - Defeating GET
  2183. method hacks</a></h3>
  2184. <p>A previous section talked about GET and POST method data and
  2185. variables. If you think about it, you may be able to envision a
  2186. security issue. For example, if on a web page I have obtained
  2187. some data from a database and I pass this data along in a
  2188. variable called "data" in a POST method form. In the ensuing page
  2189. I can access this variable and do something with it. However, if
  2190. someone accessed this second page directly and put a
  2191. "?data=something" right in the URL thereby doing a GET method
  2192. variable set, they have effectively circumvented the original
  2193. POST method form.</p>
  2194. <p>PHP provides a <em>SecureVar()</em> function which is used to
  2195. mark variables names as being secure variables. These secure
  2196. variables can only be set directly in a PHP script, or they can
  2197. come from a POST method form. They cannot be set using the GET
  2198. method variable definition mechanism. From our above scenario, if
  2199. we placed the line:</p>
  2200. <pre>
  2201. &lt;?SecureVar("data")&gt;
  2202. </pre>
  2203. <p>Near the beginning of our second page, then the GET method
  2204. trick would not work. The "data" variable would appear to be
  2205. empty unless it came directly from the POST method form on the
  2206. first page.</p>
  2207. <p>The <em>SecureVar()</em> actually takes a regular expression
  2208. as its argument, so you can mark patterns of variable names that
  2209. should be treated in this secure manner. For example,</p>
  2210. <pre>
  2211. &lt;?SecureVar(".*data.*")&gt;
  2212. </pre>
  2213. <p>Would mark any variable with the word "data" anywhere in their
  2214. name as being secure.</p>
  2215. <p>Please note that POST-method forms are not intrinsically
  2216. secure. People can emulate the posting of any data to a form by
  2217. simply telnetting to the HTTP port on your system. You need to
  2218. take appropriate security measures to stop people from doing this
  2219. if in fact security is a concern.</p>
  2220. <hr />
  2221. <h3><a name="overload" id="overload">Overloaded Operators and
  2222. dealing with variable types</a></h3>An overloaded operator is an
  2223. operator like '+' for example which can do different things based
  2224. on the types of the expressions it is asked to operate on.
  2225. <p>The problem is that PHP understands 3 variable types. Integer,
  2226. Double and String. When a variable is first assigned, PHP
  2227. automatically figures out the variable type.</p>
  2228. <p>ie.</p>
  2229. <pre>
  2230. $a = 1; Type would be integer
  2231. $b = 1.5; Type would be double
  2232. $c = "1"; Type would be string
  2233. </pre>
  2234. <p>Now, what happens when you do something like:</p>
  2235. <pre>
  2236. $d = $a + $c;
  2237. </pre>
  2238. <p>The parser looks at the first part of the arithmetic
  2239. expression and uses that to type the result and thus also the
  2240. nature of the arithmetic that is to be done. In the above case
  2241. since $a is an integer, $d will be an integer and an integer
  2242. addition is done giving the result:</p>
  2243. <pre>
  2244. $d = 2 Type is integer
  2245. </pre>
  2246. <p>Therefore:</p>
  2247. <pre>
  2248. $d = $c + $a
  2249. </pre>
  2250. <p>Results in:</p>
  2251. <pre>
  2252. $d = "11" Type is string
  2253. </pre>
  2254. <p>The above makes sense to me, and once you understand it, it is
  2255. probably workable. However, when more complex expressions are
  2256. used it can get extremely confusing.</p>
  2257. <p>The solution is a simple type casting mechanism. In reality
  2258. all variables are automatically converted to all 3 types, and an
  2259. internal flag just marks what type the variable actually is. So,
  2260. when I say:</p>
  2261. <pre>
  2262. $a = 1;
  2263. </pre>
  2264. <p>Internally in the symbol table I store 3 versions.</p>
  2265. <pre>
  2266. Integer: 1 &lt;-- flag
  2267. Double : 1.0
  2268. String : "1"
  2269. </pre>
  2270. <p>The <em>SetType()</em> function can move this flag indicating
  2271. the type of the variable.</p>
  2272. <pre>
  2273. SetType($a,"double");
  2274. </pre>
  2275. <p>This would force $a to be treated as a double from then
  2276. on.</p>
  2277. <p>The <em>GetType()</em> function returns the type.
  2278. <tt>GetType($a)</tt> would return "double" in this case.</p>
  2279. <p>Functions also exist to return the 3 various types without
  2280. moving the type flag.</p>
  2281. <pre>
  2282. IntVal($a) returns 1
  2283. DoubleVal($a) returns 1.0
  2284. StrVal($a) returns "1"
  2285. </pre>
  2286. <p>This doesn't change the overloaded operator nature of the PHP
  2287. variables, but it does give you some tools to better deal with
  2288. them. PHP is not not a full-fledged Perl look-alike. It has to be
  2289. small and fast. Perl deals with the overloaded operator pitfall
  2290. by forcing something like the '+' operator to only work on
  2291. numbers. If you want to add strings, you must use the '.'
  2292. operator. Once you start having separate operators for each type
  2293. you start making the language much more complex. ie. you can't
  2294. use '==' for stings, you now would use 'eq'. I don't see the
  2295. point, especially for something like PHP where most of the
  2296. scripts will be rather simple and in most cases written by
  2297. non-programmers who want a language with a basic logical syntax
  2298. that doesn't have too high a learning curve.</p>
  2299. <hr />
  2300. <h3><a name="quiet" id="quiet">Suppressing Errors from function
  2301. calls</a></h3>
  2302. <p>It may be desirable in certain circumstances to ignore fatal
  2303. errors which may be reported by specific PHP functions. For
  2304. example, you may want to ignore errors from a dbmopen() call and
  2305. simply check the return value of the call without having error
  2306. messages appear on the web screen. This can be done by putting
  2307. the "@" character in front of the function call. ie.</p>
  2308. <pre>
  2309. $err_code = @dbmopen($filename,"w");
  2310. </pre>
  2311. <p>The actual error message that would have been printed can be
  2312. checked by looking at the PHP internal variable,
  2313. <strong>$phperrmsg</strong>.</p>
  2314. <p>A more general approach to suppress error message printing is
  2315. to use the <a href="#seterrorreporting">SetErrorReporting()</a>
  2316. function. With this function error printing can be disabled for
  2317. entire blocks of code by preceding the block with a call
  2318. like:</p>
  2319. <pre>
  2320. SetErrorReporting(0);
  2321. </pre>
  2322. <p>This turns off all errors. They can then be re-enabled later
  2323. with:</p>
  2324. <pre>
  2325. SetErrorReporting(1);
  2326. </pre>
  2327. <hr />
  2328. <h3><a name="funcs" id="funcs">Internal
  2329. Functions</a></h3><a href="function"></a>
  2330. <p>PHP has a number of built-in functions. Functions are called
  2331. in the same manner as they are called in the C language. Some
  2332. take one or more arguments, and some return values which can then
  2333. be assigned to a variable or used as an argument to another
  2334. function. For example:</p>
  2335. <pre>
  2336. &lt;?$t=time()&gt;
  2337. </pre>
  2338. <p>This assigns the return value of the <em>time()</em> function
  2339. to the <em>t</em> variable.</p>
  2340. <h3>Alphabetical List of Functions</h3>
  2341. <dl>
  2342. <dt><a name="abs" id="abs"><big>Abs(arg)</big></a></dt>
  2343. <dd>
  2344. <p>Abs returns the absolute value of arg.</p>
  2345. </dd>
  2346. <dt><a name="ada_close" id="ada_close"><big>Ada_Close(connection_id)</big></a></dt>
  2347. <dd>
  2348. <p>Ada_Close will close down the connection to the Adabas
  2349. server associated with the given connection identifier.</p>
  2350. <p>This function is only available if Adabas support has been
  2351. enabled in PHP.</p>
  2352. </dd>
  2353. <dt><a name="ada_connect" id="ada_connect"><big>$connection = Ada_Connect(data source name, username,
  2354. password)</big></a></dt>
  2355. <dd>
  2356. <p>Ada_Connect opens a connection to a Adabas server. Each of
  2357. the arguments should be a quoted string. The first parameter
  2358. (data source name) is a string in the form
  2359. "servername:databasename". The servername (but not the colon)
  2360. can be omitted if you want to access a local database. This
  2361. function returns a connection_id. This identifier is needed
  2362. by other Adabas functions. You can have multiple connections
  2363. open at once. This function will return <strong>0</strong> on
  2364. error.</p>
  2365. <p>This function is only available if Adabas support has been
  2366. enabled in PHP.</p>
  2367. </dd>
  2368. <dt><a name="ada_exec" id="ada_exec"><big>$result =
  2369. Ada_Exec(connection_id, query_string)</big></a></dt>
  2370. <dd>
  2371. <p>Ada_Exec will send an SQL statement to the Adabas server
  2372. specified by the connection_id. The connection_id must be a
  2373. valid identifier that was returned by Ada_Connect or the
  2374. special value <strong>0</strong>. If connection_id is 0,
  2375. ada_exec tries to establish or to use a connection with the
  2376. parameters given with the <a href="#directives">configuration
  2377. directives</a> <em>phpAdaDefDB, phpAdaUser</em> and
  2378. <em>phpAdaPW</em>.<br />
  2379. The return value of this function is an identifier to be used
  2380. to access the results by other Adabas functions. This
  2381. function will return <strong>0</strong> on error. It will
  2382. return <strong>1</strong> when the command executed correctly
  2383. but is not expected to return data (insert or update
  2384. commands, for example). Note that selects which return no
  2385. data will still return a valid result greater than 1.</p>
  2386. <p>This function is only available if Adabas support has been
  2387. enabled in PHP.</p>
  2388. </dd>
  2389. <dt><a name="ada_fetchrow" id="ada_fetchrow"><big>Ada_FetchRow(result_id [,row_number])</big></a></dt>
  2390. <dd>
  2391. <p>Ada_FetchRow fetches a row of the data that was returned
  2392. by Ada_Exec. After Ada_FetchRow is called, the fields of that
  2393. row can be access with Ada_Result. If no rownumber is given,
  2394. Ada_FetchRow will try to fetch the next row in the result
  2395. set. Every time Ada_FetchRow is called a new row can be
  2396. accessed by Ada_Result. If Ada_FetchRow was succesful (there
  2397. was a row), <strong>1</strong> is returned, if there are no
  2398. more rows, Ada_FetchRow will return <strong>0</strong>. The
  2399. return value of Ada_FetchRow can be used as the condition of
  2400. a while loop. Calls to Ada_FetchRow() with and without
  2401. rownumber can be mixed. To step through the result more than
  2402. once, you can call Ada_FetchRow() with rownumber 1 and then
  2403. continue with Ada_FetchRow() without rownumber to review the
  2404. result.</p>
  2405. <p>This function is only available if Adabas support has been
  2406. enabled in PHP.</p>
  2407. </dd>
  2408. <dt><a name="ada_fieldname" id="ada_fieldname"><big>Ada_FieldName(result_id, field_number)</big></a></dt>
  2409. <dd>
  2410. <p>Ada_FieldName will return the name of the field occupying
  2411. the given column number in the given Adabas result
  2412. identifier. Field numbering starts from 0.</p>
  2413. <p>This function is only available if Adabas support has been
  2414. enabled in PHP.</p>
  2415. </dd>
  2416. <dt><a name="ada_fieldnum" id="ada_fieldnum"><big>Ada_FieldNum(result_id, field_name)</big></a></dt>
  2417. <dd>
  2418. <p>Ada_FieldNum will return the number of the column slot
  2419. that corresponds to the named field in the given Adabas
  2420. result identifier. Field numbering starts at 0. This function
  2421. will return <strong>-1</strong> on error.</p>
  2422. <p>This function is only available if Adabas support has been
  2423. enabled in PHP.</p>
  2424. </dd>
  2425. <dt><a name="ada_fieldtype" id="ada_fieldtype"><big>Ada_FieldType(result_id,
  2426. field_name|field_number)</big></a></dt>
  2427. <dd>
  2428. <p>Ada_FieldType will return the SQL type of the field
  2429. referecend by name or number in the given Adabas result
  2430. identifier. Note: Field numbering starts from 0.</p>
  2431. <p>This function is only available if Adabas support has been
  2432. enabled in PHP.</p>
  2433. </dd>
  2434. <dt><a name="ada_freeresult" id="ada_freeresult"><big>Ada_FreeResult(result_id)</big></a></dt>
  2435. <dd>
  2436. <p>Ada_FreeResult only needs to be called if you are worried
  2437. about using too much memory while your script is running. All
  2438. result memory will automatically be freed when the script is
  2439. finished. But, if you are sure you are not going to need the
  2440. result data anymore in a script, you may call Ada_FreeResult
  2441. with the result identifier as an argument and the associated
  2442. result memory will be freed.</p>
  2443. <p>This function is only available if Adabas support has been
  2444. enabled in PHP.</p>
  2445. </dd>
  2446. <dt><a name="ada_numfields" id="ada_numfields"><big>Ada_NumFields(result_id)</big></a></dt>
  2447. <dd>
  2448. <p>Ada_NumFields will return the number of fields (columns)
  2449. in a Adabas result. The argument is a valid result identifier
  2450. returned by Ada_Exec. This function will return
  2451. <strong>-1</strong> on error.</p>
  2452. <p>This function is only available if Adabas support has been
  2453. enabled in PHP.</p>
  2454. </dd>
  2455. <dt><a name="ada_numrows" id="ada_numrows"><big>Ada_NumRows(result_id)</big></a></dt>
  2456. <dd>
  2457. <p>Ada_NumRows will return the number of rows in a Adabas
  2458. result. The argument is a valid result identifier returned by
  2459. Ada_Exec. This function will return <strong>-1</strong> on
  2460. error. For INSERT, UPDATE, DELETE statements Ada_NumRows()
  2461. returns the number of rows affected. For a SELECT clause this
  2462. is the number of rows available.</p>
  2463. <p>This function is only available if Adabas support has been
  2464. enabled in PHP.</p>
  2465. </dd>
  2466. <dt><a name="ada_result" id="ada_result"><big>Ada_Result(result_id, field name | index)</big></a></dt>
  2467. <dd>
  2468. <p>Ada_Result will return values from a result identifier
  2469. produced by Ada_Exec. The field name specify what cell in the
  2470. row to return. Instead of naming the field, you may use the
  2471. field index as an unquoted number. Field indices start from
  2472. 0. If the requested field is of code type BYTE (binary) or is
  2473. longer than 4096 bytes, the contents is sent directly to the
  2474. client. Hint: [VAR]CHAR BYTE fields can be returned into a
  2475. php variable by using the HEX() db function; e. g. SELECT
  2476. HEX(SYSKEY) SYSKEY FROM MYTABLE.</p>
  2477. <p>This function is only available if Adabas support has been
  2478. enabled in PHP.</p>
  2479. </dd>
  2480. <dt><a name="ada_resultall" id="ada_resultall"><big>Ada_ResultAll(result_id [,format])</big></a></dt>
  2481. <dd>
  2482. <p>Ada_ResultAll will print all rows from a result identifier
  2483. produced by Ada_Exec. The result is printed in HTML table
  2484. format. With the optional formatstring additional overall
  2485. table formatting can be done (e. g. bgcolor= will set
  2486. background color, &gt;caption&gt; &lt;/caption to set
  2487. caption). Note: The contents of "format" will be inserted
  2488. into the HTML table tag like this &lt;table format
  2489. &gt;...</p>
  2490. <p>This function is only available if Adabas support has been
  2491. enabled in PHP.</p>
  2492. </dd>
  2493. <dt><a name="addslashes" id="addslashes"><big>AddSlashes(arg)</big></a></dt>
  2494. <dd>
  2495. <p>Escapes any $ \ or ' (if MAGIC_QUOTES is set) with a
  2496. backslash. See also <a href=
  2497. "#stripslashes">StripSlashes()</a>.</p>
  2498. </dd>
  2499. <dt><a name="asort" id="asort"><big>ASort(array)</big></a></dt>
  2500. <dd>
  2501. <p>Sort is used to sort a PHP associative array in ascending
  2502. order. Use ARSort() for descending order. Unlike the <a href=
  2503. "#sort">Sort()</a> function, ASort() maintains index-value
  2504. pairings. It understands the three variable types and will
  2505. sort alphabetically if the array contains strings, and
  2506. numerically if the array contains numbers. In the case of an
  2507. array which contains a mixture of types, the first type in
  2508. the array will specify the sort method. Note that if you are
  2509. going to sort a non-associative array, you should use the
  2510. <a href="#sort">Sort()</a> function.</p>
  2511. </dd>
  2512. <dt><a name="bindec" id="bindec"><big>BinDec(binary_string)</big></a></dt>
  2513. <dd>
  2514. <p>BinDec returns the decimal equivalent of the binary number
  2515. represented by the binary_string argument. The largest number
  2516. that can be converted is 31 bits long or 4294967295 in
  2517. decimal. See also the <a href="#decbin">DecBin()</a>
  2518. function.</p>
  2519. </dd>
  2520. <dt><a name="ceil" id="ceil"><big>Ceil(value)</big></a></dt>
  2521. <dd>
  2522. <p>Ceil() rounds a floating point value up to the next
  2523. integer. The return value is of type double (floating point)
  2524. such that it can be used properly in complex equations. To
  2525. get an integer type back, use: <tt>$new =
  2526. IntVal(Ceil($value));</tt><br />
  2527. See also <a href="#floor">Floor()</a>.</p>
  2528. </dd>
  2529. <dt><a name="chdir" id="chdir"><big>ChDir(dir)</big></a></dt>
  2530. <dd>
  2531. <p>ChDir changes the current working directory to the
  2532. directory specified in the argument.</p>
  2533. </dd>
  2534. <dt><a name="chgrp" id="chgrp"><big>ChGrp(file,group)</big></a></dt>
  2535. <dd>
  2536. <p>ChGrp changes the group id of the specified file.</p>
  2537. </dd>
  2538. <dt><a name="chmod" id="chmod"><big>ChMod(file,perms)</big></a></dt>
  2539. <dd>
  2540. <p>ChMod changes the file permissions of the specified file.
  2541. The <em>perms</em> parameter must be specified in <a href=
  2542. "#octal">octal</a> notation. eg. ChMod($filename,0755)</p>
  2543. </dd>
  2544. <dt><a name="chown" id="chown"><big>ChOwn(file,owner)</big></a></dt>
  2545. <dd>
  2546. <p>ChOwn changes the specified file to be owned by the
  2547. specified owner. Note that this will only work if the PHP/FI
  2548. binary is running as root (which is not generally a good
  2549. idea).</p>
  2550. </dd>
  2551. <dt><a name="chop" id="chop"><big>Chop(string)</big></a></dt>
  2552. <dd>
  2553. <p>Chop removes all trailing whitespaces including new-lines,
  2554. tabs and spaces and returns the new string.</p>
  2555. </dd>
  2556. <dt><a name="chr" id="chr"><big>Chr(arg)</big></a></dt>
  2557. <dd>
  2558. <p>Chr returns the ASCII character represented by the integer
  2559. argument.</p>
  2560. </dd>
  2561. <dt><a name="clearstack" id="clearstack"><big>ClearStack()</big></a></dt>
  2562. <dd>
  2563. <p>The ClearStack() function is a hack/workaround for a
  2564. deficiency in the PHP parser. This dificiency is that PHP
  2565. only has a single expression stack. When inside a
  2566. user-defined function this expression stack is never cleared
  2567. because its contents may be needed within a complex
  2568. expression in the context from which the user-defined
  2569. function was called. This means that if you have a while loop
  2570. with a lot of iterations inside a user-defined function, you
  2571. may be chewing up a lot of stack space. You may even be
  2572. hitting the max data space limit. You can put a call to
  2573. ClearStack() inside your while loop to prevent this memory
  2574. consumption, but the trade-off is that you cannot use your
  2575. function within any sort of context. ie. you have to assign
  2576. the output of the function to a temporary variable and then
  2577. use this temporary variable in whatever context you need.</p>
  2578. </dd>
  2579. <dt><a name="clearstatcache" id="clearstatcache"><big>
  2580. ClearStatCache()</big></a></dt>
  2581. <dd>
  2582. <p>The stat() system call is normally an expensive operation
  2583. on most operating systems. In order to make sure that
  2584. repeated calls to the various File* functions like <a href=
  2585. "#fileperms">FilePerms()</a>, <a href=
  2586. "#fileinode">FileInode()</a>, etc. the result of the last
  2587. stat() call is always cached. If one of the File* functions
  2588. is called again with the same argument, the cached stat()
  2589. result will be used. In order to force a new stat() system
  2590. call this ClearStatCache() function may be called to clear
  2591. the cached stat() result.</p>
  2592. </dd>
  2593. <dt><a name="closedir" id="closedir"><big>
  2594. closeDir()</big></a></dt>
  2595. <dd>
  2596. <p>closeDir closes a directory opened using the <a href=
  2597. "#opendir">openDir</a> function.</p>
  2598. </dd>
  2599. <dt><a name="closelog" id="closelog"><big>
  2600. CloseLog()</big></a></dt>
  2601. <dd>
  2602. <p>CloseLog() closes the descriptor Syslog() uses to write to
  2603. the system logger. See the closelog(3) UNIX man page for more
  2604. details. See also <a href="#syslog">Syslog()</a>, <a href=
  2605. "#openlog">OpenLog()</a> and <a href=
  2606. "#initsyslog">InitSyslog()</a>.</p>
  2607. </dd>
  2608. <dt><a name="cos" id="cos"><big>
  2609. Cos(arg)</big></a></dt>
  2610. <dd>
  2611. <p>Cos returns the cosine of arg in radians. See also
  2612. <a href="#sin">Sin()</a> and <a href="#tan">Tan()</a></p>
  2613. </dd>
  2614. <dt><a name="count" id="count"><big>
  2615. Count(array)</big></a></dt>
  2616. <dd>
  2617. <p>Count returns the number of items in an array variable. If
  2618. the variable is not an array, the return value will be 1
  2619. (because a normal variable is similar to an array with only
  2620. one item). If the variable is not defined, the return value
  2621. will be 0.</p>
  2622. </dd>
  2623. <dt><a name="crypt" id="crypt"><big>
  2624. Crypt(string,[salt])</big></a></dt>
  2625. <dd>
  2626. <p>Crypt will encrypt a string using the standard Unix DES
  2627. encryption method. Arguments are a string to be encrypted and
  2628. an optional two-character salt string to base the encryption
  2629. on. See the Unix man page for your crypt function for more
  2630. information. If you do not have a crypt function on your Unix
  2631. system, you can use Michael Glad's public domain UFC-Crypt
  2632. package which was developed in Denmark and hence not
  2633. restricted by US export laws as long as you ftp it from an
  2634. non-US site.</p>
  2635. </dd>
  2636. <dt><a name="date" id="date"><big>
  2637. Date(format,time)</big></a></dt>
  2638. <dd>
  2639. <p>The Date function is used to display times and dates in
  2640. various ways. The function takes a format string and a time
  2641. as arguments. If the time argument is left off, the current
  2642. time and date will be used. The time argument is specified as
  2643. an integer in number of seconds since the Unix Epoch on Jan.1
  2644. 1970. The format string is used to indicate which date/time
  2645. components should be displayed and how they should be
  2646. formatted. The following characters are recognized within the
  2647. format string. Any unrecognized character is printed
  2648. verbosely:</p>
  2649. <ul>
  2650. <li><tt>Y - Year eg. 1995</tt></li>
  2651. <li><tt>y - Year eg. 95</tt></li>
  2652. <li><tt>M - Month eg. Oct</tt></li>
  2653. <li><tt>m - Month eg. 10</tt></li>
  2654. <li><tt>F - Month eg. October</tt></li>
  2655. <li><tt>D - Day eg. Fri</tt></li>
  2656. <li><tt>l - Day eg. Friday</tt></li>
  2657. <li><tt>d - Day eg. 27</tt></li>
  2658. <li><tt>z - Day of the year eg. 299</tt></li>
  2659. <li><tt>H - Hours in 24 hour format eg. 13</tt></li>
  2660. <li><tt>h - Hours in 12 hour format eg. 1</tt></li>
  2661. <li><tt>i - Minutes eg. 5</tt></li>
  2662. <li><tt>s - Seconds eg. 40</tt></li>
  2663. <li><tt>U - Seconds since epoch eg. 814807830</tt></li>
  2664. <li><tt>A - AM/PM</tt></li>
  2665. <li><tt>a - am/pm</tt></li>
  2666. </ul>
  2667. <p>See also the <a href="#mktime">MkTime()</a> function.</p>
  2668. </dd>
  2669. <dt><a name="dblist" id="dblist"><big>
  2670. dbList()</big></a></dt>
  2671. <dd>
  2672. <p>dbList outputs information about the db support compiled
  2673. into PHP.</p>
  2674. </dd>
  2675. <dt><a name="dbmclose" id="dbmclose"><big>
  2676. dbmClose(filename)</big></a></dt>
  2677. <dd>
  2678. <p>dbmClose simply closes the specified dbm file. It will
  2679. also unlock any lock files, so it is important to close any
  2680. dbm files that have been opened.</p>
  2681. </dd>
  2682. <dt><a name="dbmdelete" id="dbmdelete"><big>
  2683. dbmDelete(filename,key)</big></a></dt>
  2684. <dd>
  2685. <p>dbmDelete will delete the key/content pair specified by
  2686. the given key argument.</p>
  2687. </dd>
  2688. <dt><a name="dbmexists" id="dbmexists"><big>
  2689. dbmExists(filename,key)</big></a></dt>
  2690. <dd>
  2691. <p>dbmExists will return 1 if the key exists and 0
  2692. otherwise.</p>
  2693. </dd>
  2694. <dt><a name="dbmfetch" id="dbmfetch"><big>
  2695. dbmFetch(filename,key)</big></a></dt>
  2696. <dd>
  2697. <p>dbmFetch will return the content string associated with
  2698. the given key.</p>
  2699. </dd>
  2700. <dt><a name="dbmfirstkey" id="dbmfirstkey"><big>
  2701. dbmFirstKey(filename)</big></a></dt>
  2702. <dd>
  2703. <p>dbmFirstKey returns the first key in the dbm file. Note
  2704. that no particular order is guaranteed since the order
  2705. depends on hash table values calculated within the dbm
  2706. implementation. You may use the <a href="#sort">Sort</a>
  2707. function to sort arrays of data from the dbm file if
  2708. necessary.</p>
  2709. </dd>
  2710. <dt><a name="dbminsert" id="dbminsert"><big>
  2711. dbmInsert(filename,key,content)</big></a></dt>
  2712. <dd>
  2713. <p>dbmInsert inserts a new key/content data pair into a dbm
  2714. file. If the key already exists, the insert will fail.</p>
  2715. </dd>
  2716. <dt><a name="dbmnextkey" id="dbmnextkey"><big>
  2717. dbmNextKey(filename,key)</big></a></dt>
  2718. <dd>
  2719. <p>dbmNextKey returns the next key after the specified key.
  2720. By calling <strong>dbmfirstkey()</strong> followed by
  2721. successive calls to <strong>dbmnextkey()</strong> it is
  2722. possible to visit every key/content pair in the dbm file.</p>
  2723. </dd>
  2724. <dt><a name="dbmopen" id="dbmopen"><big>
  2725. dbmOpen(filename,mode)</big></a></dt>
  2726. <dd>
  2727. <p>dbmOpen() opens a dbm file. The first argument is the
  2728. full-path filename of the dbm file to be opened and the
  2729. second is the file open mode which is one of <b>"r"</b>,
  2730. <b>"n"</b> or <b>"w"</b> for read, new (implies write) and
  2731. write respectively. If ndbm support is used, ndbm will
  2732. actually create <em>filename.dir</em> and
  2733. <em>filename.pag</em> files. gdbm only uses one file, as does
  2734. the internal flat ascii file support, and Berkeley's libdb
  2735. create a <em>filename.db</em> file. Note that PHP does its
  2736. own file locking in addition to any file locking that may be
  2737. done by the dbm library itself. PHP does not delete the
  2738. <em>.lck</em> files it creates. It uses these files simply as
  2739. fixed inodes on which to do the file locking. For more
  2740. information on dbm files, see your Unix man pages, or obtain
  2741. GNU's gdbm from <a href=
  2742. "ftp://prep.ai.mit.edu/pub/gnu">ftp://prep.ai.mit.edu/pub/gnu</a>.</p>
  2743. </dd>
  2744. <dt><a name="dbmreplace" id="dbmreplace"><big>
  2745. dbmReplace(filename,key,content)</big></a></dt>
  2746. <dd>
  2747. <p>dbmReplace is similar to the <strong>dbminsert()</strong>
  2748. function, the only difference being that if the key already
  2749. exists, the old content string will be replaced with the
  2750. new.</p>
  2751. </dd>
  2752. <dt><a name="decbin" id="decbin"><big>
  2753. DecBin(number)</big></a></dt>
  2754. <dd>
  2755. <p>DecBin returns a string containing a binary representation
  2756. of the given number argument. The largest number that can be
  2757. converted is 31 bits long or 4294967295 in decimal. See also
  2758. the <a href="#bindec">BinDec()</a> function.</p>
  2759. </dd>
  2760. <dt><a name="dechex" id="dechex"><big>
  2761. DecHex(number)</big></a></dt>
  2762. <dd>
  2763. <p>DecHex converts a decimal number to a hexadecimal string.
  2764. See also the <a href="#hexdec">HexDec()</a> function.</p>
  2765. </dd>
  2766. <dt><a name="decoct" id="decoct"><big>
  2767. DecOct(number)</big></a></dt>
  2768. <dd>
  2769. <p>DecOct converts a decimal number to an octal number. See
  2770. also <a href="#octdec">OctDec()</a>.</p>
  2771. </dd>
  2772. <dt><a name="doubleval" id="doubleval"><big>
  2773. doubleval(variable)</big></a></dt>
  2774. <dd>
  2775. <p>doubleval returns the double (floating point) value of the
  2776. variable. See also the <a href="#strval">strval()</a> and
  2777. <a href="#intval">intval()</a> functions.</p>
  2778. </dd>
  2779. <dt><a name="echo" id="echo"><big>Echo
  2780. [format_string] expression [, expression
  2781. [,...]]</big></a></dt>
  2782. <dd>
  2783. <p>Echo is not a function. ie. you do not put brackets around
  2784. the arguments to it. It is used to display results of PHP
  2785. functions or PHP variables. See the <a href="#escapes">Escape
  2786. Character Section</a> for a list of special characters
  2787. supported. The format_string is optional and if not present,
  2788. no output formatting will be done. The format string is
  2789. similar to the format string of the C <em>printf</em>
  2790. function. See the man page for <em>printf</em> for more
  2791. details. Up to 5 expressions can be printed with a single
  2792. echo command. If you try to print more you will get a parser
  2793. error. Note that the types of the expressions are not
  2794. relevant. The expressions are automagically converted to the
  2795. appropriate types as specified by the format string if one is
  2796. present. If you want to format something and assign the
  2797. formatted string to a variable instead of displaying it, use
  2798. the <a href="#sprintf">sprintf()</a> function.</p>
  2799. <p>The following conversions are supported,</p>
  2800. <blockquote>
  2801. <dl>
  2802. <dt>%d %i</dt>
  2803. <dd>Print a signed decimal number.</dd>
  2804. <dt>%o</dt>
  2805. <dd>Print an octal number.</dd>
  2806. <dt>%u</dt>
  2807. <dd>Print an unsigned decimal number.</dd>
  2808. <dt>%x %X</dt>
  2809. <dd>Print a hexadecimal number.</dd>
  2810. <dt>%f</dt>
  2811. <dd>Print a floating-point number.</dd>
  2812. <dt>%e %E</dt>
  2813. <dd>Print a floating-point number in scientific
  2814. notation.</dd>
  2815. <dt>%g %G</dt>
  2816. <dd>Print a floating-point number in scientific notation
  2817. or normal notation, as appropriate.</dd>
  2818. <dt>%c</dt>
  2819. <dd>Print a single character.</dd>
  2820. <dt>%s</dt>
  2821. <dd>Print a string of characters.</dd>
  2822. <dt>%%</dt>
  2823. <dd>Print a literal percent-sign.</dd>
  2824. </dl>
  2825. <p>The following flags are accepted.</p>
  2826. <dl>
  2827. <dt>'-'</dt>
  2828. <dd>Left-justify the output within the field-width.</dd>
  2829. <dt>'+'</dt>
  2830. <dd>Ensure that all integers are signed (with a
  2831. plus/minus sign).</dd>
  2832. <dt>' '</dt>
  2833. <dd>Similar to '+', but uses a space instead of a
  2834. plus-sign.</dd>
  2835. <dt>'#'</dt>
  2836. <dd>Print prefixes in front of hex and octal numbers
  2837. designating them as such.</dd>
  2838. <dt>'''</dt>
  2839. <dd>Separate the digits into groups (usually
  2840. comma-separated groups of three).</dd>
  2841. <dt>'0'</dt>
  2842. <dd>Pad the field-width with zeros.</dd>
  2843. </dl>
  2844. <p>All of these flags are dependent upon whether or not
  2845. your C library's printf function supports them (the ''',
  2846. for example, is a GNU extension).</p>
  2847. <p>Most conversions will accept a field width and a
  2848. precision, as shown in the <tt>demo_echo.html</tt> file in
  2849. the directory /examples. It is not necessary to specify any
  2850. type modifiers, and, in fact, PHP will complain if the type
  2851. modifier does not make sense (which is almost always the
  2852. case). PHP will complain about (and refuse to accept)
  2853. anything that it does not recognize. Any extra arguments
  2854. given that are not required by the format-string are
  2855. ignored.</p>
  2856. </blockquote>
  2857. </dd>
  2858. <dt><a name="end" id="end"><big>
  2859. End(variable)</big></a></dt>
  2860. <dd>
  2861. <p>End moves the internal array pointer for the given
  2862. variable to the last item of the array and returns the value
  2863. of this item. This is useful for traversing an associative
  2864. array in reverse order. See also <a href="#reset">Reset()</a>
  2865. and <a href="#prev">Prev()</a>. The following example would
  2866. traverse an associative array in reverse order:</p>
  2867. <pre>
  2868. &lt;?
  2869. Reset($array);
  2870. $first_key = key($array);
  2871. End($array);
  2872. $k = key($array);
  2873. while($k != $first_key);
  2874. echo $array[$k];
  2875. prev($array);
  2876. $k = key($array);
  2877. endwhile;
  2878. echo $array[$k];
  2879. &gt;
  2880. </pre>
  2881. </dd>
  2882. <dt><a name="ereg" id="ereg"><big>
  2883. ereg(expr,arg[,regs])</big></a></dt>
  2884. <dd>
  2885. <p>ereg returns non-zero if the regular expression is matched
  2886. in the argument string. For example, the condition,
  2887. <tt>&lt;?if (ereg("^This.*", "This is an example
  2888. string")&gt;</tt> would be true since the "^This.*"
  2889. expression says to match the word <strong>This</strong> at
  2890. the beginning of the string and then match any characters
  2891. afterwards. If the <em>regs</em> argument is present, then
  2892. match registers are filled into positions 0-10 in the array
  2893. named by the <em>regs</em> argument. Register 0 will always
  2894. contain the full matched string. For more information on
  2895. regular expressions, see the <a href="#regexp">regular
  2896. expression section</a> of this document.</p>
  2897. </dd>
  2898. <dt><a name="eregi" id="eregi"><big>
  2899. eregi(expr,arg[,regs])</big></a></dt>
  2900. <dd>
  2901. <p>eregi is identical to the <a href="#ereg">ereg()</a>
  2902. function except for the fact that the regular expression is
  2903. applied such that upper/lower case is ignored.</p>
  2904. </dd>
  2905. <dt><a name="ereg_replace" id="ereg_replace"><big>
  2906. ereg_replace(expr,replace,arg)</big></a></dt>
  2907. <dd>
  2908. <p>ereg_Replace scans the entire argument string and replaces
  2909. any portions of the string matched by the given expression
  2910. with the replacement string. For example, in the string,
  2911. <tt>"This is an example string"</tt> we could very easily
  2912. replace every space with a dash with the command:
  2913. <strong>ereg_replace(" ","-","This is an example
  2914. string")</strong>.For more information on regular
  2915. expressions, see the <a href="#regexp">regular expression
  2916. section</a> of this document.</p>
  2917. </dd>
  2918. <dt><a name="eregi_replace" id="eregi_replace"><big>
  2919. eregi_replace(expr,replace,arg)</big></a></dt>
  2920. <dd>
  2921. <p>eregi_replace is identical to the <a href=
  2922. "#ereg_replace">ereg_replace()</a> function except for the
  2923. fact that the regular expression is applied such that
  2924. upper/lower case is ignored.</p>
  2925. </dd>
  2926. <dt><a name="escapeshellcmd" id="escapeshellcmd"><big>
  2927. EscapeShellCmd(string)</big></a></dt>
  2928. <dd>
  2929. <p>EscapeShellCmd escapes any characters in a string that
  2930. might be used to trick a shell command into executing
  2931. arbitrary commands. This function should be used to make sure
  2932. that any data coming from user input is escaped before this
  2933. data is passed to the <a href="#exec">Exec()</a> or <a href=
  2934. "#system">System()</a> functions. A standard use would
  2935. be:</p>
  2936. <pre>
  2937. &lt;?system(EscapeShellCmd($cmd))&gt;
  2938. </pre>
  2939. </dd>
  2940. <dt><a name="eval" id="eval"><big>
  2941. Eval(string)</big></a></dt>
  2942. <dd>
  2943. <p>Eval takes the contents of the string argument and treats
  2944. it like a mini PHP/FI script. It will execute it as a
  2945. separate PHP/FI script. Any variables set or accessed from
  2946. inside the eval will be from the global reference frame in
  2947. the current context of the eval statement in the script.
  2948. Variable substitution is done on the string arguments, so if
  2949. variables are to be used in the string expression they should
  2950. be escaped. Some examples:</p>
  2951. <pre>
  2952. $a = "echo phpversion();";
  2953. eval($a);
  2954. eval("echo phpversion();");
  2955. eval("\$a=1; echo \$a;");
  2956. </pre>
  2957. </dd>
  2958. <dt><a name="exec" id="exec"><big>
  2959. Exec(command_string [, array
  2960. [,return_var]])</big></a></dt>
  2961. <dd>
  2962. <p>Exec executes the given unix command, however it does not
  2963. output anything. It simply returns the last line from the
  2964. result of the command. If you need to execute a command and
  2965. have all the data from the command passed directly back
  2966. without any interference, use the <a href=
  2967. "#passthru">PassThru()</a> function. If the array argument is
  2968. present, then the specified array will be filled with every
  2969. line of output from the unix command starting at the end of
  2970. the array. Make sure you <a href="#unset">UnSet</a> the array
  2971. before the call if your array already contains elements and
  2972. you want to start filling it at array element 0. If the
  2973. return_var argument is present along with the array argument,
  2974. then the return status of the executed unix command will be
  2975. written to this variable. Note that if you are going to allow
  2976. data coming from user input to be passed to this Exec
  2977. function, then you should be using the <a href=
  2978. "#escpapeshellcmd">EscapeShellCmd()</a> function to make sure
  2979. that users cannot trick the system into executing arbitrary
  2980. commands. See also the <a href="#system">system()</a>
  2981. function.</p>
  2982. </dd>
  2983. <dt><a name="exit" id="exit"><big>
  2984. Exit</big></a></dt>
  2985. <dd>
  2986. <p>The Exit command is used to terminate parsing right away
  2987. as soon as this tag is parsed.</p>
  2988. </dd>
  2989. <dt><a name="exp" id="exp"><big>
  2990. Exp(arg)</big></a></dt>
  2991. <dd>
  2992. <p>Exp returns e raised to the power of arg. See also
  2993. <a href="#pow">pow()</a></p>
  2994. </dd>
  2995. <dt><a name="fclose" id="fclose"><big>
  2996. fclose($fd)</big></a></dt>
  2997. <dd>
  2998. <p>fclose() closes a file opened by <a href=
  2999. "#fopen">fopen()</a>. The argument is a file pointer index as
  3000. returned by the fopen() call.</p>
  3001. </dd>
  3002. <dt><a name="feof" id="feof"><big>
  3003. feof($fd)</big></a></dt>
  3004. <dd>
  3005. <p>Feof returns true if the file referred to by the file
  3006. pointer index argument has hit end-of-file.</p>
  3007. </dd>
  3008. <dt><a name="fgets" id="fgets"><big>
  3009. fgets($fd,bytes)</big></a></dt>
  3010. <dd>
  3011. <p>fgets() reads a line from a file opened by <a href=
  3012. "#fopen">fopen()</a>. Arguments are a file pointer index as
  3013. returned by fopen() and the max number of bytes to read.
  3014. Reading ends when max number of bytes have been read, or on
  3015. an end of line. This is similar to the C fgets() call. See
  3016. also <a href="#fputs">fputs()</a>.</p>
  3017. </dd>
  3018. <dt><a name="fgetss" id="fgetss"><big>
  3019. fgetss($fd,bytes)</big></a></dt>
  3020. <dd>
  3021. <p>Identical to the fgets() function, except this one tries
  3022. to strip off any HTML tags or PHP/FI script tags as it is
  3023. reading the file.</p>
  3024. </dd>
  3025. <dt><a name="file" id="file"><big>$array =
  3026. File(filename)</big></a></dt>
  3027. <dd>
  3028. <p>File reads the entire file and returns an array with each
  3029. array element containing a line of the file starting with
  3030. array index <strong>0</strong>.</p>
  3031. </dd>
  3032. <dt><a name="fileatime" id="fileatime"><big>
  3033. fileAtime(filename)</big></a></dt>
  3034. <dd>
  3035. <p>fileAtime returns the time of last data access. If the
  3036. file does not exist, or if it for some other reason could not
  3037. be accessed, this function returns -1. If repeated calls to
  3038. fileAtime and the rest ofthe file* functions are to be made
  3039. and the file being accessed might change or disappear, the
  3040. <a href="#clearstatcache">ClearStatCache()</a> should be
  3041. called before the call to the file* function.</p>
  3042. </dd>
  3043. <dt><a name="filectime" id="filectime"><big>
  3044. fileCtime(filename)</big></a></dt>
  3045. <dd>
  3046. <p>fileCtime returns the time of last status change. If the
  3047. file does not exist, or if it for some other reason could not
  3048. be accessed, this function returns -1. If repeated calls to
  3049. fileCtime and the rest ofthe file* functions are to be made
  3050. and the file being accessed might change or disappear, the
  3051. <a href="#clearstatcache">ClearStatCache()</a> should be
  3052. called before the call to the file* function.</p>
  3053. </dd>
  3054. <dt><a name="filegroup" id="filegroup"><big>
  3055. fileGroup(filename)</big></a></dt>
  3056. <dd>
  3057. <p>fileGroup returns the group id of the owner of the file.
  3058. If the file does not exist, or if it for some other reason
  3059. could not be accessed, this function returns -1. If repeated
  3060. calls to fileGroup and the rest ofthe file* functions are to
  3061. be made and the file being accessed might change or
  3062. disappear, the <a href="#clearstatcache">ClearStatCache()</a>
  3063. should be called before the call to the file* function.</p>
  3064. </dd>
  3065. <dt><a name="fileinode" id="fileinode"><big>
  3066. fileInode(filename)</big></a></dt>
  3067. <dd>
  3068. <p>fileInode returns the file's inode. If the file does not
  3069. exist, or if it for some other reason could not be accessed,
  3070. this function returns -1. If repeated calls to fileInode and
  3071. the rest ofthe file* functions are to be made and the file
  3072. being accessed might change or disappear, the <a href=
  3073. "#clearstatcache">ClearStatCache()</a> should be called
  3074. before the call to the file* function.</p>
  3075. </dd>
  3076. <dt><a name="filemtime" id="filemtime"><big>
  3077. fileMtime(filename)</big></a></dt>
  3078. <dd>
  3079. <p>fileMtime returns the time of last data modification. If
  3080. the file does not exist, or if it for some other reason could
  3081. not be accessed, this function returns -1. If repeated calls
  3082. to fileMtime and the rest ofthe file* functions are to be
  3083. made and the file being accessed might change or disappear,
  3084. the <a href="#clearstatcache">ClearStatCache()</a> should be
  3085. called before the call to the file* function.</p>
  3086. </dd>
  3087. <dt><a name="fileowner" id="fileowner"><big>
  3088. fileOwner(filename)</big></a></dt>
  3089. <dd>
  3090. <p>fileOwner returns the uid of the owner of the file. If the
  3091. file does not exist, or if it for some other reason could not
  3092. be accessed, this function returns -1. If repeated calls to
  3093. fileOwner and the rest ofthe file* functions are to be made
  3094. and the file being accessed might change or disappear, the
  3095. <a href="#clearstatcache">ClearStatCache()</a> should be
  3096. called before the call to the file* function.</p>
  3097. </dd>
  3098. <dt><a name="fileperms" id="fileperms"><big>
  3099. filePerms(filename)</big></a></dt>
  3100. <dd>
  3101. <p>filePerms returns the permission bits of the file. This is
  3102. the <em>st_mode</em> field of the Unix C stat structure. If
  3103. the file does not exist, or if it for some other reason could
  3104. not be accessed, this function returns -1. If repeated calls
  3105. to filePerms and the rest ofthe file* functions are to be
  3106. made and the file being accessed might change or disappear,
  3107. the <a href="#clearstatcache">ClearStatCache()</a> should be
  3108. called before the call to the file* function.</p>
  3109. </dd>
  3110. <dt><a name="filesize" id="filesize"><big>
  3111. fileSize(filename)</big></a></dt>
  3112. <dd>
  3113. <p>fileSize returns the size of the file in bytes. If the
  3114. file does not exist, or if it for some other reason could not
  3115. be accessed, this function returns -1. If repeated calls to
  3116. fileSize and the rest ofthe file* functions are to be made
  3117. and the file being accessed might change or disappear, the
  3118. <a href="#clearstatcache">ClearStatCache()</a> should be
  3119. called before the call to the file* function.</p>
  3120. </dd>
  3121. <dt><a name="filetype" id="filetype"><big>
  3122. fileType(filename)</big></a></dt>
  3123. <dd>
  3124. <p>fileType returns the type of the file. The return values
  3125. are one of: "dir", "file","fifo","char", "block", or "link".
  3126. These are for, directory, regular file, fifo special,
  3127. character special, block special and symbolic link,
  3128. respectively.</p>
  3129. </dd>
  3130. <dt><a name="floor" id="floor"><big>
  3131. Floor(value)</big></a></dt>
  3132. <dd>
  3133. <p>Floor() rounds a floating point value down to the previous
  3134. integer. The return value is of type double (floating point)
  3135. such that it can be used properly in complex equations. To
  3136. get an integer type back, use: <tt>$new =
  3137. IntVal(Floor($value));</tt><br />
  3138. See also <a href="#ceil">Ceil()</a>.</p>
  3139. </dd>
  3140. <dt><a name="flush" id="flush"><big>
  3141. Flush()</big></a></dt>
  3142. <dd>
  3143. <p>The Flush() function is used to Flush the output buffer.
  3144. For the Apache module, it flushes Apache's output buffer, and
  3145. for the CGI version it simply flushes stdout. When running as
  3146. a CGI under Apache, the server will buffer the CGI script's
  3147. output, so this Flush() function won't help much there. Look
  3148. at running your script as an nph- script if you are running
  3149. the CGI version of PHP under the Apache web server. Or,
  3150. alternatively, run the Apache module version of PHP.</p>
  3151. </dd>
  3152. <dt><a name="fopen" id="fopen"><big>$fp =
  3153. fopen(filename,mode)</big></a></dt>
  3154. <dd>
  3155. <p>fopen() opens a file and returns a file pointer index. If
  3156. the file could not be opened the function returns -1. It is
  3157. similar to the C fopen() call. The filename argument is the
  3158. relative or absolute path to the file to be opened, and the
  3159. mode argument is one of, "r", "r+", "w", "w+", "a", "a+". See
  3160. the Unix man page on the fopen() call for more information.
  3161. See also the <a href="#popen">popen()</a> function
  3162. description. See also the <a href="#fclose">fclose()</a>
  3163. function description.</p>
  3164. <p>Example:</p>
  3165. <pre>
  3166. $fp = fopen("/home/rasmus/file.txt","r");
  3167. </pre>
  3168. </dd>
  3169. <dt><a name="fputs" id="fputs"><big>
  3170. fputs(fp,string)</big></a></dt>
  3171. <dd>
  3172. <p>fputs() writes a line to a file opened by <a href=
  3173. "#fopen">fopen()</a>. Arguments are a file pointer index as
  3174. returned by fopen() and the string to write. Note that the
  3175. string argument may contain the special escape characters,
  3176. <strong>\n</strong>, <strong>\r</strong> and
  3177. <strong>\t</strong> to output newlines, carriage returns and
  3178. tabs respectively. See also <a href="#fgets">fgets()</a>.</p>
  3179. </dd>
  3180. <dt><a name="fpassthru" id="fpassthru"><big>
  3181. FPassThru(fp)</big></a></dt>
  3182. <dd>
  3183. <p>FPassThru() outputs all remaining data on <i>fp</i>
  3184. directly. It is different from <a href=
  3185. "#readfile">ReadFile()</a> in that it can also handle files
  3186. opened with <a href="#fsockopen">fsockopen()</a>. It differs
  3187. from <a href="#passthru">PassThru()</a> in that it does not
  3188. handle commands, but opened files. FPassThru() returns the
  3189. number of bytes read and written.</p>
  3190. </dd>
  3191. <dt><a name="fseek" id="fseek"><big>
  3192. fseek(fp,pos)</big></a></dt>
  3193. <dd>
  3194. <p>fseek() positions a file pointer identified by the $fd
  3195. argument which is the return value of the <a href=
  3196. "#fopen">fopen()</a> call. The file pointer is positioned at
  3197. the beginning of the file plus the offset specified by the
  3198. <strong>pos</strong> argument. See also <a href=
  3199. "#ftell">ftell()</a> and <a href="#rewind">rewind()</a>.</p>
  3200. </dd>
  3201. <dt><a name="fsockopen" id="fsockopen"><big>fp =
  3202. fsockopen(hostname,port)</big></a></dt>
  3203. <dd>
  3204. <p>fsockopen() opens a socket connection and returns a file
  3205. pointer index. This file pointer index can be used by
  3206. <a href="#fgets">fgets</a>, <a href="#fputs">fputs</a> and
  3207. <a href="#fclose">fclose</a>. Arguments are a hostname and a
  3208. port number. Return values are: -3 if the socket couldn't be
  3209. created, -4 if the dns lookup on the hostname failed, -5 if
  3210. the connection was refused or it timed out, -6 if the actual
  3211. fdopen() call failed or -7 if the setvbuf() call failed. If
  3212. the port number is 0, then the hostname argument will be
  3213. treated as a filename of a Unix domain socket if your
  3214. operating system support Unix domain sockets.</p>
  3215. </dd>
  3216. <dt><a name="ftell" id="ftell"><big>pos =
  3217. ftell(fp)</big></a></dt>
  3218. <dd>
  3219. <p>ftell() returns the position of a file pointer identified
  3220. by the fp argument which is the return value of the <a href=
  3221. "#fopen">fopen()</a> call. The position can later be used as
  3222. an argument to fseek(). See also <a href="#fseek">fseek()</a>
  3223. and <a href="#rewind">rewind()</a>.</p>
  3224. </dd>
  3225. <dt><a name="getaccdir" id="getaccdir"><big>
  3226. getAccDir()</big></a></dt>
  3227. <dd>
  3228. <p>getAccDir returns the directory where PHP access
  3229. configuration files are kept. The access configuration
  3230. filenames come from the numerical user id of the user whose
  3231. access configurations they represent.</p>
  3232. </dd>
  3233. <dt><a name="getenv" id="getenv"><big>
  3234. GetEnv(string)</big></a></dt>
  3235. <dd>
  3236. <p>GetEnv returns the value of the environment value
  3237. specified by <em>string</em>. Normally this function is not
  3238. used because environment variables are available to PHP/FI
  3239. directly. If a reference is made to a variable which is not
  3240. found in the internal symbol table, then the environment
  3241. space is automatically searched. GetEnv should be used when
  3242. it is necessary to ensure that an environment variable has
  3243. not been overwritten by normal PHP/FI variable. Security
  3244. mechanisms that rely on http server-defined variables like
  3245. REMOTE_ADDR and REMOTE_HOST should load these variables using
  3246. GetEnv as opposed to referencing them directly as
  3247. $REMOTE_ADDR to avoid someone making up a fake form and
  3248. posting the data to your server and thereby bypassing
  3249. whatever security mechanism you might have.</p>
  3250. </dd>
  3251. <dt><a name="gethostbyname" id="gethostbyname"><big>
  3252. getHostByName(domain_name)</big></a></dt>
  3253. <dd>
  3254. <p>getHostByName converts the given domain name into an IP
  3255. address in nnn.nnn.nnn.nnn format.</p>
  3256. </dd>
  3257. <dt><a name="gethostbyaddr" id="gethostbyaddr"><big>
  3258. getHostByAddr(ip_address)</big></a></dt>
  3259. <dd>
  3260. <p>getHostByAddr converts the given IP address in
  3261. nnn.nnn.nnn.nnn format into a fully qualified domain
  3262. name.</p>
  3263. </dd>
  3264. <dt><a name="getimagesize" id="getimagesize"><big>
  3265. GetImageSize(filename)</big></a></dt>
  3266. <dd>
  3267. <p>The GetImageSize() function takes either a full path
  3268. filename, or a relative path relative to the location of the
  3269. calling script. It returns a 3 element array consisting of
  3270. width, height and type. Width and height are in pixels, and a
  3271. type of 1 means GIF, a 2 indicates a JPG file and a 3
  3272. indicates a PNG file. Other file types are not supported. The
  3273. fourth element in the returned array is a string containing,
  3274. "width=x height=y" that is suitable for using directly in an
  3275. IMG tag. It is important to note that the GD image library is
  3276. not needed to use this function. An example follows:</p>
  3277. <pre>
  3278. &lt;?
  3279. $result = GetImageSize("img/flag.jpg");
  3280. &gt;
  3281. &lt;IMG SRC="img/flag.jpg" ?echo $result[3]&gt; &gt;
  3282. </pre>
  3283. </dd>
  3284. <dt><a name="getlastaccess" id="getlastaccess"><big>
  3285. getLastAccess()</big></a></dt>
  3286. <dd>
  3287. <p>getLastAccess returns the date and time in unix time
  3288. format of the last time the current page was access. This
  3289. value can be passed to the <a href="#date">Date()</a>
  3290. function for formatting.<br />
  3291. This function is only available if PHP was compiled with
  3292. Access Logging enabled.</p>
  3293. </dd>
  3294. <dt><a name="getlastbrowser" id="getlastbrowser"><big>
  3295. getLastbrowser()</big></a></dt>
  3296. <dd>
  3297. <p>getLastBrowser returns the identification string of
  3298. browser the last user to access the current page used.<br />
  3299. This function is only available if PHP was compiled with
  3300. Access Logging enabled.</p>
  3301. </dd>
  3302. <dt><a name="getlastemail" id="getlastemail"><big>
  3303. getLastEmail()</big></a></dt>
  3304. <dd>
  3305. <p>getLastEmail returns the E-Mail address of the last user
  3306. to access the current page.<br />
  3307. This function is only available if PHP was compiled with
  3308. Access Logging enabled.</p>
  3309. </dd>
  3310. <dt><a name="getlasthost" id="getlasthost"><big>
  3311. getLastHost()</big></a></dt>
  3312. <dd>
  3313. <p>getLastHost returns the hostname of the last user to
  3314. access the current page.<br />
  3315. This function is only available if PHP was compiled with
  3316. Access Logging enabled.</p>
  3317. </dd>
  3318. <dt><a name="getlastmod" id="getlastmod"><big>
  3319. getLastMod()</big></a></dt>
  3320. <dd>
  3321. <p>getLastMod returns the date and time in unix time format
  3322. of the last time the current page was modified. This value
  3323. can be passed to the <a href="#date">Date()</a> function for
  3324. formatting.<br />
  3325. This function is only available if PHP was compiled with
  3326. Access Logging enabled.</p>
  3327. </dd>
  3328. <dt><a name="getlastref" id="getlastref"><big>
  3329. getLastref()</big></a></dt>
  3330. <dd>
  3331. <p>getLastRef returns the URL of the referring document of
  3332. the last user to access the current page.<br />
  3333. This function is only available if PHP was compiled with
  3334. Access Logging enabled.</p>
  3335. </dd>
  3336. <dt><a name="getlogdir" id="getlogdir"><big>
  3337. getLogDir()</big></a></dt>
  3338. <dd>
  3339. <p>getLogDir returns the top-level directory under which PHP
  3340. log files can be found. The actual log files are in
  3341. directories under this directory. Each subdirectory is the
  3342. numerical user id of the user to whom the log files belong.
  3343. Then within each directory a series of dbm log files are
  3344. found, each with the numerical inode of the file they
  3345. represent as the primary component of the filename.</p>
  3346. </dd>
  3347. <dt><a name="getmyinode" id="getmyinode"><big>
  3348. getMyInode()</big></a></dt>
  3349. <dd>
  3350. <p>getMyInode returns the numerical inode of the current HTML
  3351. file.</p>
  3352. </dd>
  3353. <dt><a name="getmypid" id="getmypid"><big>
  3354. getMyPid()</big></a></dt>
  3355. <dd>
  3356. <p>getMyPid() returns the current process id of the PHP
  3357. parsing process.</p>
  3358. </dd>
  3359. <dt><a name="getmyuid" id="getmyuid"><big>
  3360. getMyUid()</big></a></dt>
  3361. <dd>
  3362. <p>getMyUid returns the numerical user id of the owner of the
  3363. current HTML file.</p>
  3364. </dd>
  3365. <dt><a name="getrandmax" id="getrandmax"><big>
  3366. getRandMax()</big></a></dt>
  3367. <dd>
  3368. <p>getRandMax returns the maximum random number the <a href=
  3369. "#rand">Rand</a> function will return. If the value returned
  3370. does not seem to be accurate, have a look in the php.h source
  3371. file in the PHP distribution for more information.</p>
  3372. </dd>
  3373. <dt><a name="getstartlogging" id="getstartlogging"><big>
  3374. getStartLogging()</big></a></dt>
  3375. <dd>
  3376. <p>getStartLogging returns the time and date in Unix time
  3377. format when logging commenced on the current page. This is
  3378. more accurate when mSQL-based logging is used since a
  3379. timestamp is kept in each log file. For dbm-logging the time
  3380. returned is the time the user's log directory was
  3381. created.</p>
  3382. </dd>
  3383. <dt><a name="gettoday" id="gettoday"><big>
  3384. getToday()</big></a></dt>
  3385. <dd>
  3386. <p>getToday returns the total number of hits the current page
  3387. has had since 12 midnight local time.<br />
  3388. This function is only available if PHP was compiled with
  3389. Access Logging enabled.</p>
  3390. </dd>
  3391. <dt><a name="gettotal" id="gettotal"><big>
  3392. getTotal()</big></a></dt>
  3393. <dd>
  3394. <p>getTotal returns the total number of hits the current page
  3395. has had since access logging was started on the page.<br />
  3396. This function is only available if PHP was compiled with
  3397. Access Logging enabled.</p>
  3398. </dd>
  3399. <dt><a name="gettype" id="gettype"><big>
  3400. GetType(variable)</big></a></dt>
  3401. <dd>
  3402. <p>GetType returns the type of the variable. The return value
  3403. is a string and it is one of, "integer", "double" or
  3404. "string". See also the <a href="#settype">SetType()</a>
  3405. function</p>
  3406. </dd>
  3407. <dt><a name="gmdate" id="gmdate"><big>
  3408. gmDate(format,time)</big></a></dt>
  3409. <dd>
  3410. <p>gmDate is identical to the <a href="#date">Date</a>
  3411. function except for the fact that it uses Greenwich Mean Time
  3412. instead of the current local time.</p>
  3413. </dd>
  3414. <dt><a name="header" id="header"><big>
  3415. Header(header_string)</big></a></dt>
  3416. <dd>
  3417. <p>The Header command is used at the top of an HTML file to
  3418. send raw HTTP header strings. See the <a href=
  3419. "http://www.w3.org/Protocols/rfc2068/rfc2068">HTTP
  3420. Specification</a> for more information on raw http headers.
  3421. Remember that the Header() command must be used before any
  3422. actual output is sent either by normal HTML tags or by PHP
  3423. echo commands.<br />
  3424. Usage examples can be found in the <a href="#http_auth">HTTP
  3425. Authentication</a> section.</p>
  3426. </dd>
  3427. <dt><a name="hexdec" id="hexdec"><big>
  3428. HexDec(hex_string)</big></a></dt>
  3429. <dd>
  3430. <p>HexDec converts a hexadecimal string to a decimal number.
  3431. See also the <a href="#dechex">DecHex()</a> function.</p>
  3432. </dd>
  3433. <dt><a name="htmlspecialchars" id=
  3434. "htmlspecialchars"><big>HtmlSpecialChars(string)</big></a></dt>
  3435. <dd>
  3436. <p>HtmlSpecialChars converts any characters with ascii codes
  3437. in the string argument between 160 and 255 inclusive to their
  3438. corresponding HTML Entity names. The function returns the
  3439. converted string. The <b>&lt;</b>, <b>&gt;</b>, <b>&amp;</b>
  3440. and <b>"</b> are also converted.</p>
  3441. </dd>
  3442. <dt><a name="imagearc" id="imagearc"><big>
  3443. ImageArc(im, cx, cy, w, h, s, e, col)</big></a></dt>
  3444. <dd>
  3445. <p>ImageArc draws a partial ellipse centered at cx,cy (top
  3446. left is 0,0) in the image represented by <a href=
  3447. "#imagecreate">im</a>. w and h specifies the ellipse's width
  3448. and height respectively while the start and end points are
  3449. specified in degrees indicated by the s and e
  3450. arguments.<br />
  3451. This function is only available if GD support has been
  3452. enabled in PHP.</p>
  3453. </dd>
  3454. <dt><a name="imagechar" id="imagechar"><big>
  3455. ImageChar(im, size, x, y, c, col)</big></a></dt>
  3456. <dd>
  3457. <p>ImageChar draws the character c in the image identified by
  3458. <a href="#imagecreate">im</a> at coordinates x,y (top left is
  3459. 0,0) in colour col. The size argument can be 1, 2, 3, 4 or 5
  3460. indicating the size of the font to be used. 1 is the smallest
  3461. and 5 is the largest.<br />
  3462. This function is only available if GD support has been
  3463. enabled in PHP.</p>
  3464. </dd>
  3465. <dt><a name="imagecharup" id="imagecharup"><big>
  3466. ImageCharUp(im, size, x, y, c, col)</big></a></dt>
  3467. <dd>
  3468. <p>ImageCharUp draws the character c vertically in the image
  3469. identified by <a href="#imagecreate">im</a> at coordinates
  3470. x,y (top left is 0,0) in colour col. The size argument can be
  3471. 1, 2, 3, 4 or 5 indicating the size of the font to be used. 1
  3472. is the smallest and 5 is the largest.<br />
  3473. This function is only available if GD support has been
  3474. enabled in PHP.</p>
  3475. </dd>
  3476. <dt><a name="imagecolorallocate" id=
  3477. "imagecolorallocate"><big>col =
  3478. ImageColorAllocate(im, red, green, blue)</big></a></dt>
  3479. <dd>
  3480. <p>ImageColorAllocate returns a colour identifier
  3481. representing the colour composed of the given RGB components.
  3482. The im argument is the return from the <a href=
  3483. "#imagecreate">ImageCreate</a> function. ImageColorAllocate
  3484. must be called to create each colour that is to be used in
  3485. the image represented by im.<br />
  3486. This function is only available if GD support has been
  3487. enabled in PHP.</p>
  3488. </dd>
  3489. <dt><a name="imagecolortransparent" id=
  3490. "imagecolortransparent"><big>
  3491. ImageColorTransparent(im, col)</big></a></dt>
  3492. <dd>
  3493. <p>ImageColorTransparent sets the transparent colour in the
  3494. im image to col. im is the image identifier returned by
  3495. <a href="#imagecreate">ImageCreate</a> and col is the colour
  3496. identifier returned by <a href=
  3497. "#imagecolorallocate">ImageColorAllocate</a>. This function
  3498. is only available if GD support has been enabled in PHP.</p>
  3499. </dd>
  3500. <dt><a name="imagecopyresized" id=
  3501. "imagecopyresized"><big>ImageCopyResized(dst_im,
  3502. src_im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH
  3503. )</big></a></dt>
  3504. <dd>
  3505. <p>ImageCopyResized copies a rectangular portion of one image
  3506. to another image. <em>dst_im</em> is the destination image,
  3507. <em>src_im</em> is the source image identifier. If the source
  3508. and destination coordinates and width and heights differ,
  3509. appropriate stretching or shrinking of the image fragment
  3510. will be performed. The coordinates refer to the upper left
  3511. corner. This function can be used to copy regions within the
  3512. same image (if <em>dst_im</em> is the same as
  3513. <em>src_im</em>) but if the regions overlap the results will
  3514. be unpredictable.<br />
  3515. This function is only available if GD support has been
  3516. enabled in PHP.</p>
  3517. </dd>
  3518. <dt><a name="imagecreate" id="imagecreate"><big>im =
  3519. ImageCreate(x_size, y_size)</big></a></dt>
  3520. <dd>
  3521. <p>ImageCreate returns an image identifier representing a
  3522. blank image of size x_size by y_size.<br />
  3523. This function is only available if GD support has been
  3524. enabled in PHP.</p>
  3525. </dd>
  3526. <dt><a name="imagecreatefromgif" id=
  3527. "imagecreatefromgif"><big>im =
  3528. ImageCreateFromGif(filename)</big></a></dt>
  3529. <dd>
  3530. <p>ImageCreateFromGif returns an image identifier
  3531. representing the image obtained from the given
  3532. <em>filename</em>.<br />
  3533. This function is only available if GD support has been
  3534. enabled in PHP.</p>
  3535. </dd>
  3536. <dt><a name="imagedestroy" id="imagedestroy"><big>
  3537. ImageDestroy(im)</big></a></dt>
  3538. <dd>
  3539. <p>ImageDestroy frees any memory associated with image im. im
  3540. is the image identifier returned by the <a href=
  3541. "#imagecreate">ImageCreate</a> function. This function is
  3542. only available if GD support has been enabled in PHP.</p>
  3543. </dd>
  3544. <dt><a name="imagefill" id="imagefill"><big>
  3545. ImageFill(im, x, y, col)</big></a></dt>
  3546. <dd>
  3547. <p>ImageFill performs a flood fill starting at coordinate x,y
  3548. (top left is 0,0) with colour col in image im.<br />
  3549. This function is only available if GD support has been
  3550. enabled in PHP.</p>
  3551. </dd>
  3552. <dt><a name="imagefilledpolygon" id=
  3553. "imagefilledpolygon"><big>ImageFilledPolygon(im,
  3554. points, num_points, col)</big></a></dt>
  3555. <dd>
  3556. <p>ImageFilledPolygon creates a filled polygon in image
  3557. <a href="#imagecreate">im</a>. points is a PHP array
  3558. containing the polygon's vertices. ie. points[0] = x0,
  3559. points[1] = y0, points[2] = x1, points[3] = y1, etc.
  3560. num_points is the total number of vertices.<br />
  3561. This function is only available if GD support has been
  3562. enabled in PHP.</p>
  3563. </dd>
  3564. <dt><a name="imagefilledrectangle" id=
  3565. "imagefilledrectangle"><big>ImageFilledRectangle(im,
  3566. x1, y1, x2, y2, col)</big></a></dt>
  3567. <dd>
  3568. <p>ImageFilledRectangle creates a filled rectangle of colour
  3569. col in image im starting at upper left coordinate x1,y1 and
  3570. ending at bottom right coordinate x2,y2. 0,0 is the top left
  3571. corner of the image.<br />
  3572. This function is only available if GD support has been
  3573. enabled in PHP.</p>
  3574. </dd>
  3575. <dt><a name="imagefilltoborder" id=
  3576. "imagefilltoborder"><big>ImageFillToBorder(im, x, y,
  3577. border, col)</big></a></dt>
  3578. <dd>
  3579. <p>ImageFillToBorder performs a flood fill whose border
  3580. colour is defined by border. The starting point for the fill
  3581. is x,y (top left is 0,0) and the region is filled with colour
  3582. col.<br />
  3583. This function is only available if GD support has been
  3584. enabled in PHP.</p>
  3585. </dd>
  3586. <dt><a name="imagegif" id="imagegif"><big>
  3587. ImageGif(im [,filename])</big></a></dt>
  3588. <dd>
  3589. <p>ImageGif creates the GIF file in filename from the image
  3590. im. The im argument is the return from the <a href=
  3591. "#imagecreate">ImageCreate</a> function. The filename
  3592. argument is optional, and if left off, the raw image stream
  3593. will be returned directly. By sending an <em>image/gif</em>
  3594. content-type using the <a href="#header">Header()</a>
  3595. function, you can create a PHP/FI script which returns GIF
  3596. images directly using this function.<br />
  3597. This function is only available if GD support has been
  3598. enabled in PHP.</p>
  3599. </dd>
  3600. <dt><a name="imageinterlace" id="imageinterlace"><big>
  3601. ImageInterlace(im, interlace)</big></a></dt>
  3602. <dd>
  3603. <p>ImageInterlace turns the interlace bit on or off. If
  3604. interlace is 1 the im image will be interlaced, and if
  3605. interlace is 0 the interlace bit is turned off. This
  3606. functions is only available if GD support has been enabled in
  3607. PHP.</p>
  3608. </dd>
  3609. <dt><a name="imageline" id="imageline"><big>
  3610. ImageLine(im, x1, y1, x2, y2, col)</big></a></dt>
  3611. <dd>
  3612. <p>ImageLine draws a line from x1,y1 to x2,y2 (top left is
  3613. 0,0) in image <a href="#imagecreate">im</a> of colour
  3614. <a href="#imagecolorallocate">col</a>.<br />
  3615. This function is only available if GD support has been
  3616. enabled in PHP.</p>
  3617. </dd>
  3618. <dt><a name="imagepolygon" id="imagepolygon"><big>
  3619. ImagePolygon(im, points, num_points, col)</big></a></dt>
  3620. <dd>
  3621. <p>ImagePolygon creates a polygon in image <a href=
  3622. "#imagecreate">im</a>. points is a PHP array containing the
  3623. polygon's vertices. ie. points[0] = x0, points[1] = y0,
  3624. points[2] = x1, points[3] = y1, etc. num_points is the total
  3625. number of vertices.<br />
  3626. This function is only available if GD support has been
  3627. enabled in PHP.</p>
  3628. </dd>
  3629. <dt><a name="imagerectangle" id="imagerectangle"><big>
  3630. ImageRectangle(im, x1, y1, x2, y2, col)</big></a></dt>
  3631. <dd>
  3632. <p>ImageRectangle creates a rectangle of colour col in image
  3633. im starting at upper left coordinate x1,y1 and ending at
  3634. bottom right coordinate x2,y2. 0,0 is the top left corner of
  3635. the image.<br />
  3636. This function is only available if GD support has been
  3637. enabled in PHP.</p>
  3638. </dd>
  3639. <dt><a name="imagesetpixel" id="imagesetpixel"><big>
  3640. ImageSetPixel(im, x, y, col)</big></a></dt>
  3641. <dd>
  3642. <p>ImageSetPixel draws a pixel at x,y (top left is 0,0) in
  3643. image <a href="#imagecreate">im</a> of colour <a href=
  3644. "#imagecolorallocate">col</a>.<br />
  3645. This function is only available if GD support has been
  3646. enabled in PHP.</p>
  3647. </dd>
  3648. <dt><a name="imagestring" id="imagestring"><big>
  3649. ImageString(im, size, x, y, s, col)</big></a></dt>
  3650. <dd>
  3651. <p>ImageString draws the string s in the image identified by
  3652. <a href="#imagecreate">im</a> at coordinates x,y (top left is
  3653. 0,0) in colour col. The size argument can be 1, 2, 3, 4 or 5
  3654. indicating the size of the font to be used. 1 is the smallest
  3655. and 5 is the largest.<br />
  3656. This function is only available if GD support has been
  3657. enabled in PHP.</p>
  3658. </dd>
  3659. <dt><a name="imagestringup" id="imagestringup"><big>
  3660. ImageStringUp(im, size, x, y, s, col)</big></a></dt>
  3661. <dd>
  3662. <p>ImageStringUp draws the string s vertically in the image
  3663. identified by <a href="#imagecreate">im</a> at coordinates
  3664. x,y (top left is 0,0) in colour col. The size argument can be
  3665. 1, 2, 3, 4 or 5 indicating the size of the font to be used. 1
  3666. is the smallest and 5 is the largest.<br />
  3667. This function is only available if GD support has been
  3668. enabled in PHP.</p>
  3669. </dd>
  3670. <dt><a name="imagesx" id="imagesx"><big>
  3671. ImageSX(im)</big></a></dt>
  3672. <dd>
  3673. <p>ImageSX returns the width of the image identified by
  3674. <em>im</em>.</p>
  3675. </dd>
  3676. <dt><a name="imagesy" id="imagesy"><big>
  3677. ImageSY(im)</big></a></dt>
  3678. <dd>
  3679. <p>ImageSY returns the height of the image identified by
  3680. <em>im</em>.</p>
  3681. </dd>
  3682. <dt><a name="include" id="include"><big>
  3683. Include(filename)</big></a></dt>
  3684. <dd>
  3685. <p>The Include command can be used to insert other files into
  3686. the current html file. This is extremely handy for headers
  3687. and footers which may need to be included in hundreds of HTML
  3688. files. By using an include command you then only need to
  3689. modify the header or footer file in one place when it needs
  3690. to be changed. Since full PHP parsing is done on the included
  3691. file, you can also use the include command to include common
  3692. PHP scripts you may have written. Sort of like having a
  3693. primitive shared library of scripts you can call from your
  3694. HTML file. You can place such common library files in one
  3695. directory and set PHP's include path and not have to refer to
  3696. the files with pathnames. For Apache module users this can be
  3697. configured with the <strong>phpIncludePath</strong>
  3698. directive, for CGI users with the PHP_INCLUDE_PATH
  3699. environment variable. This path is colon-separated just like
  3700. <code>$PATH</code> is in your UNIX shell. eg.</p>
  3701. <pre>
  3702. &lt;?include("/path/filename.txt")&gt;
  3703. </pre>
  3704. </dd>
  3705. <dt><a name="initsyslog" id="initsyslog"><big>
  3706. InitSyslog()</big></a></dt>
  3707. <dd>
  3708. <p>InitSyslog() defines some PHP variables that you need when
  3709. using OpenLog() and Syslog(). These variables are not defined
  3710. by default for efficiency reasons. The variables are named in
  3711. the same way as in the &lt;syslog.h&gt; C include file (such
  3712. as $LOG_LOCAL0). See your syslog(3) UNIX manual page for more
  3713. details. See also <a href="#initsyslog">InitSyslog()</a>,
  3714. <a href="#syslog">Syslog()</a> and <a href=
  3715. "#closelog">CloseLog()</a>.</p>
  3716. </dd>
  3717. <dt><a name="intval" id="intval"><big>
  3718. intval(variable)</big></a></dt>
  3719. <dd>
  3720. <p>intval returns the long integer value of the variable. See
  3721. also the <a href="#strval">strval()</a> and <a href=
  3722. "#doubleval">doubleval()</a> functions.</p>
  3723. </dd>
  3724. <dt><a name="isset" id="isset"><big>
  3725. IsSet(variable)</big></a></dt>
  3726. <dd>
  3727. <p>The IsSet function returns 1 if the given variable is
  3728. defined, and 0 if it isn't.</p>
  3729. </dd>
  3730. <dt><a name="key" id="key"><big>
  3731. Key(variable)</big></a></dt>
  3732. <dd>
  3733. <p>Key returns the key of the current array item. The current
  3734. item is determined by the position of the array pointer for
  3735. the given variable. This array pointer may be manipulated
  3736. with the <a href="#reset">Reset()</a>, <a href=
  3737. "#end">End()</a>, <a href="#next">Next()</a>, and <a href=
  3738. "#prev">Prev()</a> functions. This function is mainly used
  3739. for determining the key value for an item in an associative
  3740. array, although it will work for normal array as well.</p>
  3741. </dd>
  3742. <dt><a name="link" id="link"><big>
  3743. Link(target,link)</big></a></dt>
  3744. <dd>
  3745. <p>Link() creates a hard link. See the <a href=
  3746. "#symlink">Symlink()</a> function for creating symbolic links
  3747. (soft) links. See also <a href="#readlink">ReadLink</a> and
  3748. <a href="#LinkInfo">LinkInfo</a> functions.</p>
  3749. </dd>
  3750. <dt><a name="linkinfo" id="linkinfo"><big>
  3751. LinkInfo(path)</big></a></dt>
  3752. <dd>
  3753. <p>LinkInfo returns the st_dev field of the UNIX C stat
  3754. structure returned by the lstat system call. This function is
  3755. used to verify if a link (pointed to by path) really exists
  3756. (using the same method as the S_ISLNK macro defined in
  3757. stat.h). Returns -1 in case of error.</p>
  3758. </dd>
  3759. <dt><a name="log" id="log"><big>
  3760. Log(arg)</big></a></dt>
  3761. <dd>
  3762. <p>Log returns the natural logarithm of arg.</p>
  3763. </dd>
  3764. <dt><a name="log10" id="log10"><big>
  3765. Log10(arg)</big></a></dt>
  3766. <dd>
  3767. <p>Log10 returns the base-10 logarithm of arg.</p>
  3768. </dd>
  3769. <dt><a name="logas" id="logas"><big>
  3770. LogAs(filename)</big></a></dt>
  3771. <dd>
  3772. <p>The LogAs() function will treat the hit on the current
  3773. page as if it as actually received on the argument
  3774. filename.</p>
  3775. </dd>
  3776. <dt><a name="mail" id="mail"><big>
  3777. Mail(to,subject,message[,headers])</big></a></dt>
  3778. <dd>
  3779. <p>Mail automatically mails the message specified in the
  3780. message argument to the receiver specified in the to
  3781. argument. Multiple recipients can be specified by spaces
  3782. between them in the to argument.</p>
  3783. <p>eg.</p>
  3784. <pre>
  3785. mail("rasmus@lerdorf.on.ca",
  3786. "My Subject",
  3787. "Line 1\nLine 2\nLine 3");
  3788. </pre>If a fourth string argument is passed, this string is
  3789. inserted at the end of the header, example:
  3790. <pre>
  3791. mail("ssb@guardian.no", "the subject", $message,
  3792. "X-Mailer: PHP/FI " + phpversion());
  3793. </pre>
  3794. </dd>
  3795. <dt><a name="max" id="max"><big>
  3796. Max(array)</big></a></dt>
  3797. <dd>
  3798. <p>Max returns the maximum value of a PHP array. ie. it will
  3799. search through the entire array looking for the max element.
  3800. If it is an array of strings, the returned string is the
  3801. string which would be alphabetically last in the array if it
  3802. were sorted.</p>
  3803. </dd>
  3804. <dt><a name="md5" id="md5"><big>
  3805. Md5(message)</big></a></dt>
  3806. <dd>
  3807. <p>Md5 returns the MD5 hash of a string value.</p>
  3808. </dd>
  3809. <dt><a name="mi_close" id="mi_close"><big>
  3810. mi_Close(connection_id)</big></a></dt>
  3811. <dd>
  3812. <p>mi_Close will close down the connection to an Illustra
  3813. database associated with the given connection identifier.</p>
  3814. <p>This function is only available if Illustra support has
  3815. been enabled in PHP.</p>
  3816. </dd>
  3817. <dt><a name="mi_connect" id="mi_connect"><big>
  3818. $connection = mi_Connect(database, username,
  3819. password)</big></a></dt>
  3820. <dd>
  3821. <p>mi_Connect opens a connection to an Illustra database.
  3822. Each of the arguments should be a quoted string. This
  3823. function returns a connection_id. This identifier is needed
  3824. by other Illustra functions. You can have multiple
  3825. connections open at once. The host to connect to is governed
  3826. by the MI_PARAMS file on the machine running the PHP
  3827. executable. No support as yet for remote invocation This
  3828. function will return <strong>-1</strong> on error.</p>
  3829. <p>This function is only available if Illustra support has
  3830. been enabled in PHP.</p>
  3831. </dd>
  3832. <dt><a name="mi_dbname" id="mi_dbname"><big>
  3833. mi_DBname(connection_id)</big></a></dt>
  3834. <dd>
  3835. <p>mi_DBname will return the name of the database that the
  3836. given Illustra connection identifier is connected to.</p>
  3837. <p>This function is only available if Illustra support has
  3838. been enabled in PHP.</p>
  3839. </dd>
  3840. <dt><a name="mi_exec" id="mi_exec"><big>$result =
  3841. mi_Exec(connection_id, query_string)</big></a></dt>
  3842. <dd>
  3843. <p>mi_Exec will send an SQL statement to the Illustra
  3844. database specified by the connection_id. The connection_id
  3845. must be a valid identifier that was returned by mi_Connect.
  3846. The return value of this function is an identifier to be used
  3847. to access the results from other Illustra functions. This
  3848. function will return <strong>-1</strong> on error.</p>
  3849. <p>This function is only available if Illustra support has
  3850. been enabled in PHP.</p>
  3851. </dd>
  3852. <dt><a name="mi_fieldname" id="mi_fieldname"><big>
  3853. mi_FieldName(connection_id, result_id,
  3854. field_number)</big></a></dt>
  3855. <dd>
  3856. <p>mi_FieldName will return the name of the field occupying
  3857. the given column number with the given Illustra result and
  3858. connection identifiers. Field numbering starts from 0.</p>
  3859. <p>This function will return <strong>-1</strong> on
  3860. error.</p>
  3861. <p>This function is only available if Illustra support has
  3862. been enabled in PHP.</p>
  3863. </dd>
  3864. <dt><a name="mi_fieldnum" id="mi_fieldnum"><big>
  3865. mi_FieldNum(connection_id, result_id,
  3866. field_name)</big></a></dt>
  3867. <dd>
  3868. <p>mi_FieldNum will return the number of the column slot that
  3869. corresponds to the named field in the given Illustra result
  3870. identifier. Field numbering starts at 0. This function will
  3871. return <strong>-1</strong> on error.</p>
  3872. <p>This function is only available if Illustra support has
  3873. been enabled in PHP.</p>
  3874. </dd>
  3875. <dt><a name="mi_numfields" id="mi_numfields"><big>
  3876. mi_NumFields(connection_id, result_id)</big></a></dt>
  3877. <dd>
  3878. <p>mi_NumFields will return the number of fields (columns) in
  3879. an Illustra result. The argument is a valid result identifier
  3880. returned by mi_Exec. This function will return
  3881. <strong>-1</strong> on error.</p>
  3882. <p>This function is only available if Illustra support has
  3883. been enabled in PHP.</p>
  3884. </dd>
  3885. <dt><a name="mi_numrows" id="mi_numrows"><big>
  3886. mi_NumRows(connection_id, result_id)</big></a></dt>
  3887. <dd>
  3888. <p>mi_NumRows will return the number of rows in an Illustra
  3889. result. The argument is a valid result identifier returned by
  3890. mi_Exec. This function will return <strong>-1</strong> on
  3891. error.</p>
  3892. <p>This function is only available if Illustra support has
  3893. been enabled in PHP.</p>
  3894. </dd>
  3895. <dt><a name="mi_result" id="mi_result"><big>
  3896. mi_Result(connection_id, result_id, row_number, field
  3897. name/index)</big></a></dt>
  3898. <dd>
  3899. <p>mi_Result will return values from a result identifier
  3900. produced by mi_Exec. The row_number and field name specify
  3901. what cell in the table of results to return. Row numbering
  3902. starts from 0. Instead of naming the field, you may use the
  3903. field index as an unquoted number. Field indices start from
  3904. 0.</p>
  3905. <p>All values returned from the database are in String form,
  3906. since no type-detection is available at the present.</p>
  3907. <p>This function is only available if Illustra support has
  3908. been enabled in PHP.</p>
  3909. </dd>
  3910. <dt><a name="microtime" id="microtime"><big>
  3911. Microtime()</big></a></dt>
  3912. <dd>
  3913. <p>Microtime() returns a string "msec sec" where sec is
  3914. number of seconds since 00:00 GMT, Jan 1, 1970, and msec is
  3915. the microseconds part (as fraction of seconds). Ex
  3916. "0.87633900 825010464".<br />
  3917. This function is only available on operating systems that
  3918. support the gettimeofday() system call.</p>
  3919. </dd>
  3920. <dt><a name="min" id="min"><big>
  3921. Min(array)</big></a></dt>
  3922. <dd>
  3923. <p>Min returns the minimum value of a PHP array. ie. it will
  3924. search through the entire array looking for the min element.
  3925. If it is an array of strings, the returned string is the
  3926. string which would be alphabetically first in the array if it
  3927. were sorted.</p>
  3928. </dd>
  3929. <dt><a name="mkdir" id="mkdir"><big>
  3930. MkDir(dir,mode)</big></a></dt>
  3931. <dd>
  3932. <p>MkDir creates a directory. The <em>mode</em> parameter
  3933. must be given in <a href="#octal">octal</a> notation. eg.
  3934. MkDir("DirName",0755);</p>
  3935. </dd>
  3936. <dt><a name="mktime" id="mktime"><big>
  3937. MkTime(hour,min,sec,mon,day,year)</big></a></dt>
  3938. <dd>
  3939. <p>MkTime returns a time in Unix timestamp (long integer)
  3940. format which corresponds to the date and time specified by
  3941. the arguments. Arguments may be left out in which case the
  3942. given component is set to the current value according to the
  3943. current local time and date. These left out arguments may
  3944. only be left out from right to left. ie.
  3945. <tt>MkTime(hour,min,sec)</tt> is valid, but
  3946. <tt>MkTime(mon,day,year)</tt> is not valid. Note that this
  3947. function can be very handy as a tool for doing both date
  3948. arithmetic and date validation. You can feed it invalid
  3949. parameters, such as a month greater than 12, or a day greater
  3950. than 31 and it will figure out the right date anyway. It will
  3951. also generate an error message if any of the parameters are
  3952. outside the normal values. Use the <a href=
  3953. "#seterrorreporting">SetErrorReporting(0)</a> function to
  3954. turn this error reporting off before calling the function and
  3955. you may then check the $phperrmsg for any errors that may
  3956. have occurred.</p>
  3957. <p>eg.</p>
  3958. <pre>
  3959. SetErrorReporting(0);
  3960. $a = MkTime(0,0,0,13,1,1997);
  3961. SetErrorReporting(1);
  3962. echo $phperrmsg;
  3963. </pre>
  3964. </dd>
  3965. <dt><a name="msql" id="msql"><big>$result =
  3966. msql($database,$query)</big></a></dt>
  3967. <dd>
  3968. <p>msql sends an mSQL query. Arguments are the database name
  3969. and the query string. ie. <strong><tt>&lt;?msql("MyDatabase"
  3970. , "select * from table")&gt;</tt></strong>. The return value
  3971. from this function is a result identifier to be used to
  3972. access the results from the other msql_ functions. A result
  3973. identifier is a positive integer. The function returns
  3974. <strong>0</strong> when no result identifier is created. This
  3975. is the case with any queries that do not return anything,
  3976. such as <em>create</em>, <em>update</em>, <em>drop</em>,
  3977. <em>insert</em> and <em>delete</em>. The function will return
  3978. <strong>-1</strong> if an error occurs. A string describing
  3979. the error will be placed in $phperrmsg, and unless the
  3980. function was called as <strong>@msql()</strong> then this
  3981. error string will also be printed out. For mSQL 2.0, the
  3982. $result variable will contain the number of rows affected by
  3983. the SQL command performed. If you want your application to be
  3984. portable to mSQL 1.0, do not rely on this.<br />
  3985. This function is only available if mSQL support has been
  3986. enabled in PHP.</p>
  3987. </dd>
  3988. <dt><a name="msql_close" id="msql_close"><big>
  3989. msql_close()</big></a></dt>
  3990. <dd>
  3991. <p>msql_Close closes the socket connection to the msql
  3992. daemon, if an open connection exists. Note, since only one
  3993. concurrent mSQL session can be open at any one time, this
  3994. function does not take an argument.</p>
  3995. </dd>
  3996. <dt><a name="msql_connect" id="msql_connect"><big>
  3997. msql_connect($hostname)</big></a></dt>
  3998. <dd>
  3999. <p>msql_Connect specifies the host name or IP on which the
  4000. mSQL database engine resides. This is equivalent to the
  4001. msqlConnect() function in the mSQL C API. The one difference
  4002. between this function and the C API equivalent is that if the
  4003. function isn't called, a connection to the local host is made
  4004. by default on the first call to the msql() function. And,
  4005. there is no need for an msql_close function since only one
  4006. connection may be active at any one time. If a second call to
  4007. msql_connect() is made in a file, then the connection to the
  4008. first host is automatically closed. To explicitly connect to
  4009. the msql daemon on the local host, use:
  4010. <strong><tt>&lt;?msql_connect("localhost")&gt;</tt></strong><br />
  4011. This function is only available if mSQL support has been
  4012. enabled in PHP.</p>
  4013. </dd>
  4014. <dt><a name="msql_createdb" id="msql_createdb"><big>
  4015. msql_CreateDB($database)</big></a></dt>
  4016. <dd>
  4017. <p>msql_CreateDB creates the given database.<br />
  4018. This function is only available if mSQL support has been
  4019. enabled in PHP.</p>
  4020. </dd>
  4021. <dt><a name="msql_dbname" id="msql_dbname"><big>
  4022. msql_dbName($result,$i)</big></a></dt>
  4023. <dd>
  4024. <p>msql_dbName returns the database name stored in position
  4025. <em>$i</em> of the result pointer returned from the <a href=
  4026. "#msql_listdbs">msql_ListDbs()</a> function. The <a href=
  4027. "#msql_numrows">msql_NumRows()</a> function can be used to
  4028. determine how many database names are available.<br />
  4029. This function is only available if mSQL support has been
  4030. enabled in PHP.</p>
  4031. </dd>
  4032. <dt><a name="msql_dropdb" id="msql_dropdb"><big>
  4033. msql_DropDB($database)</big></a></dt>
  4034. <dd>
  4035. <p>msql_DropDB deletes the given mSQL database. Use this with
  4036. caution as all data in the database will be lost.<br />
  4037. This function is only available if mSQL support has been
  4038. enabled in PHP.</p>
  4039. </dd>
  4040. <dt><a name="msql_fieldflags" id="msql_fieldflags"><big>
  4041. msql_FieldFlags($result,$i)</big></a></dt>
  4042. <dd>
  4043. <p>msql_FieldFlags returns the field flags of the specified
  4044. field. Currently this is either, "not null", "primary key", a
  4045. combination of the two or "" (an empty string).<br />
  4046. This function is only available if mSQL support has been
  4047. enabled in PHP.</p>
  4048. </dd>
  4049. <dt><a name="msql_fieldlen" id="msql_fieldlen"><big>
  4050. msql_FieldLen($result,$i)</big></a></dt>
  4051. <dd>
  4052. <p>msql_FieldLen returns the length of the specified
  4053. field.<br />
  4054. This function is only available if mSQL support has been
  4055. enabled in PHP.</p>
  4056. </dd>
  4057. <dt><a name="msql_fieldname" id="msql_fieldname"><big>
  4058. msql_FieldName($result,$i)</big></a></dt>
  4059. <dd>
  4060. <p>msql_FieldName returns the name of the specified field.
  4061. Arguments to the function is the result identifier and the
  4062. field index. ie. <tt>msql_FieldName($result,2);</tt> will
  4063. return the name of the second field in the result associated
  4064. with the result identifier.<br />
  4065. This function is only available if mSQL support has been
  4066. enabled in PHP.</p>
  4067. </dd>
  4068. <dt><a name="msql_fieldtype" id="msql_fieldtype"><big>
  4069. msql_FieldType($result,$i)</big></a></dt>
  4070. <dd>
  4071. <p>msql_FieldType is similar to the msql_FieldName()
  4072. function. The arguments are identical, but the field type is
  4073. returned. This will be one of "int", "char" or "real".<br />
  4074. This function is only available if mSQL support has been
  4075. enabled in PHP.</p>
  4076. </dd>
  4077. <dt><a name="msql_freeresult" id="msql_freeresult"><big>
  4078. msql_FreeResult($result)</big></a></dt>
  4079. <dd>
  4080. <p>msql_FreeResult only needs to be called if you are worried
  4081. about using too much memory while your script is running. All
  4082. result memory will automatically be freed when the script is
  4083. finished. But, if you are sure you are not going to need the
  4084. result data anymore in a script, you may call msql_freeresult
  4085. with the result identifier as an argument and the associated
  4086. result memory will be freed.<br />
  4087. This function is only available if mSQL support has been
  4088. enabled in PHP.</p>
  4089. </dd>
  4090. <dt><a name="msql_listdbs" id="msql_listdbs"><big>
  4091. $result = msql_ListDBs()</big></a></dt>
  4092. <dd>
  4093. <p>msql_ListDBs will return a result pointer containing the
  4094. databases available from the current mSQL daemon. Use the
  4095. <a href="#msql_dbname">msql_dbName()</a> function to traverse
  4096. this result pointer.<br />
  4097. This function is only available if mSQL support has been
  4098. enabled in PHP.</p>
  4099. </dd>
  4100. <dt><a name="msql_listfields" id="msql_listfields"><big>
  4101. $result =
  4102. msql_Listfields($database,$tablename)</big></a></dt>
  4103. <dd>
  4104. <p>msql_listfields retrieves information about the the given
  4105. tablename. Arguments are the database name and the table
  4106. name. A result pointer is returned which can be used with
  4107. msql_fieldflags, msql_fieldlen, msql_fieldname,
  4108. msql_fieldtype. A result identifier is a positive integer.
  4109. The function returns -1 if a error occurs. A string
  4110. describing the error will be placed in $phperrmsg, and unless
  4111. the function was called as @msql() then this error string
  4112. will also be printed out.<br />
  4113. This function is only available if mSQL support has been
  4114. enabled in PHP.</p>
  4115. </dd>
  4116. <dt><a name="msql_listtables" id="msql_listtables"><big>
  4117. $result = msql_ListTables($database)</big></a></dt>
  4118. <dd>
  4119. <p>msql_ListTables takes a database name and result pointer
  4120. much like the <a href="#msql">msql()</a> function. The
  4121. <a href="#msql_tablename">msql_TableName()</a> function
  4122. should be used to extract the actual table names from the
  4123. result pointer.<br />
  4124. This function is only available if mSQL support has been
  4125. enabled in PHP.</p>
  4126. </dd>
  4127. <dt><a name="msql_numfields" id="msql_numfields"><big>
  4128. msql_NumFields($result)</big></a></dt>
  4129. <dd>
  4130. <p>msql_NumFields returns the number of fields in a result.
  4131. The argument is the result identifier returned by the msql()
  4132. function.<br />
  4133. This function is only available if mSQL support has been
  4134. enabled in PHP.</p>
  4135. </dd>
  4136. <dt><a name="msql_numrows" id="msql_numrows"><big>
  4137. msql_NumRows($result)</big></a></dt>
  4138. <dd>
  4139. <p>msql_NumRows simply returns the number of rows in a
  4140. result. The argument is the result identifier returned by the
  4141. msql() function.<br />
  4142. This function is only available if mSQL support has been
  4143. enabled in PHP.</p>
  4144. </dd>
  4145. <dt><a name="msql_regcase" id="msql_regcase"><big>
  4146. msql_RegCase(string)</big></a></dt>
  4147. <dd>
  4148. <p>msql_RegCase takes a string argument and converts it to
  4149. the regular expression needed to send to mSQL in order to get
  4150. a case insensitive match. This turns a string like "abc" into
  4151. "[Aa][Bb][Cc]".<br />
  4152. This function is only available if mSQL support has been
  4153. enabled in PHP.</p>
  4154. </dd>
  4155. <dt><a name="msql_result" id="msql_result"><big>
  4156. msql_Result($result,$i,field)</big></a></dt>
  4157. <dd>
  4158. <p>msql_Result displays a field from a returned record.
  4159. Arguments are the result identifier returned by the msql()
  4160. function, an integer which is the index of the record to be
  4161. viewed and a field name. The field argument supports the
  4162. "table.field" syntax for handling results from a join. This
  4163. function is perhaps best illustrated with a complete
  4164. example:</p>
  4165. <pre>
  4166. &lt;?
  4167. $name = "bob";
  4168. $result = msql($database,"select * from table where firstname='$name'");
  4169. $num = msql_numrows($result);
  4170. echo "$num records found!&lt;p&gt;";
  4171. $i=0;
  4172. while($i&lt;$num);
  4173. echo msql_result($result,$i,"fullname");
  4174. echo "&lt;br&gt;";
  4175. echo msql_result($result,$i,"address");
  4176. echo "&lt;br&gt;";
  4177. $i++;
  4178. endwhile;
  4179. &gt;
  4180. </pre>
  4181. <p>The above script connects to the mSQL engine on the local
  4182. machine, sets the <em>name</em> variable to <em>bob</em> and
  4183. sends a query which asks for all the fields from a table
  4184. where the <em>firstname</em> field is set to <em>bob</em>. It
  4185. then displays the number of records it found after which it
  4186. loops through each of the found records and displays the
  4187. <em>fullname</em> and <em>address</em> fields for each
  4188. record. As you can see, it would be trivial to add HTML
  4189. markup tags around the printed fields to format the results
  4190. in a table or in whatever manner is desired. Note that there
  4191. is no msql_connect() call. msql_connect need only be called
  4192. if a connection to a remote database is desired.</p>
  4193. <p>This function is only available if mSQL support has been
  4194. enabled in PHP.</p>
  4195. </dd>
  4196. <dt><a name="msql_tablename" id="msql_tablename"><big>
  4197. msql_TableName($result,$i)</big></a></dt>
  4198. <dd>
  4199. <p>msql_TableName takes a result pointer returned by the
  4200. <a href="#msql_listtables">msql_ListTables()</a> function as
  4201. well as an integer index and returns the name of a table. The
  4202. <a href="#msql_numrows">msql_NumRows()</a> function may be
  4203. used to determine the number of tables in the result pointer.
  4204. An example would be:</p>
  4205. <pre>
  4206. &lt;?
  4207. $result = msql_listtables("dbname");
  4208. $i=0;
  4209. while($i &lt; msql_numrows($result));
  4210. $tb_names[$i]=msql_tablename($result, $i);
  4211. echo $tb_names[$i];
  4212. echo "&lt;BR&gt;";
  4213. $i++;
  4214. endwhile;
  4215. &gt;
  4216. </pre><br />
  4217. This function is only available if mSQL support has been
  4218. enabled in PHP.
  4219. </dd>
  4220. <dt><a name="mysql" id="mysql"><big>$result =
  4221. mysql($database,$query)</big></a></dt>
  4222. <dd>
  4223. <p>mysql sends a mysql query. Arguments are the database name
  4224. and the query string. ie. <strong><tt>&lt;?mysql("MyDatabase"
  4225. , "select * from table")&gt;</tt></strong>. The return value
  4226. from this function is a result identifier to be used to
  4227. access the results from the other mysql_ functions. A result
  4228. identifier is a positive integer. The function returns
  4229. <strong>0</strong> when no result identifier is created. This
  4230. is the case with any queries that do not return anything,
  4231. such as <em>create</em>, <em>update</em>, <em>drop</em>,
  4232. <em>insert</em> and <em>delete</em>. The function will return
  4233. <strong>-1</strong> if an error occurs. A string describing
  4234. the error will be placed in $phperrmsg, and unless the
  4235. function was called as <strong>@mysql()</strong> then this
  4236. error string will also be printed out.<br />
  4237. This function is only available if mysql support has been
  4238. enabled in PHP.</p>
  4239. </dd>
  4240. <dt><a name="mysql_affected_rows" id=
  4241. "mysql_affected_rows"><big>
  4242. mysql_affected_rows()</big></a></dt>
  4243. <dd>
  4244. <p>mysql_affected_rows() returns number of rows affected by
  4245. the last INSERT, UPDATE or DELETE query.</p>
  4246. </dd>
  4247. <dt><a name="mysql_close" id="mysql_close"><big>
  4248. mysql_close()</big></a></dt>
  4249. <dd>
  4250. <p>mysql_Close closes the socket connection to the mysql
  4251. daemon, if an open connection exists.</p>
  4252. </dd>
  4253. <dt><a name="mysql_connect" id="mysql_connect"><big>
  4254. mysql_connect($hostname [,username
  4255. [,password]])</big></a></dt>
  4256. <dd>
  4257. <p>mysql_Connect specifies the host name or IP on which the
  4258. mysql database engine resides. This is equivalent to the
  4259. mysqlConnect() function in the mysql C API. The one
  4260. difference between this function and the C API equivalent is
  4261. that if the function isn't called, a connection to the local
  4262. host is made by default on the first call to the mysql()
  4263. function. And, there is no need for an mysql_close function
  4264. since only one connection may be active at any one time. If a
  4265. second call to mysql_connect() is made in a file, then the
  4266. connection to the first host is automatically closed.</p>
  4267. <p>An optional username and password may be provided. Note
  4268. that when PHP is compiled to run in <a href="#safemode">SAFE
  4269. MODE</a> then the username must either be the same as the
  4270. owner of the file being processed, or the owner of the httpd
  4271. process (usually nobody). Any other username will fail.</p>
  4272. <p>To explicitly connect to the mysql daemon on the local
  4273. host, use:
  4274. <strong><tt>&lt;?mysql_connect("localhost")&gt;</tt></strong><br />
  4275. This function is only available if mysql support has been
  4276. enabled in PHP.</p>
  4277. </dd>
  4278. <dt><a name="mysql_createdb" id="mysql_createdb"><big>
  4279. mysql_CreateDB($database)</big></a></dt>
  4280. <dd>
  4281. <p>mysql_CreateDB creates the given database.<br />
  4282. This function is only available if mysql support has been
  4283. enabled in PHP.</p>
  4284. </dd>
  4285. <dt><a name="mysql_dbname" id="mysql_dbname"><big>
  4286. mysql_dbName($result,$i)</big></a></dt>
  4287. <dd>
  4288. <p>mysql_dbName returns the database name stored in position
  4289. <em>$i</em> of the result pointer returned from the <a href=
  4290. "#mysql_listdbs">mysql_ListDbs()</a> function. The <a href=
  4291. "#mysql_numrows">mysql_NumRows()</a> function can be used to
  4292. determine how many database names are available.<br />
  4293. This function is only available if mysql support has been
  4294. enabled in PHP.</p>
  4295. </dd>
  4296. <dt><a name="mysql_dropdb" id="mysql_dropdb"><big>
  4297. mysql_DropDB($database)</big></a></dt>
  4298. <dd>
  4299. <p>mysql_DropDB deletes the given mysql database. Use this
  4300. with caution as all data in the database will be lost.<br />
  4301. This function is only available if mysql support has been
  4302. enabled in PHP.</p>
  4303. </dd>
  4304. <dt><a name="mysql_fieldflags" id=
  4305. "mysql_fieldflags"><big>mysql_FieldFlags($result,$i)</big></a></dt>
  4306. <dd>
  4307. <p>mysql_FieldFlags returns the field flags of the specified
  4308. field. Currently this is either, "not null", "primary key", a
  4309. combination of the two or "" (an empty string).<br />
  4310. This function is only available if mysql support has been
  4311. enabled in PHP.</p>
  4312. </dd>
  4313. <dt><a name="mysql_fieldlen" id="mysql_fieldlen"><big>
  4314. mysql_FieldLen($result,$i)</big></a></dt>
  4315. <dd>
  4316. <p>mysql_FieldLen returns the length of the specified
  4317. field.<br />
  4318. This function is only available if mysql support has been
  4319. enabled in PHP.</p>
  4320. </dd>
  4321. <dt><a name="mysql_fieldname" id="mysql_fieldname"><big>
  4322. mysql_FieldName($result,$i)</big></a></dt>
  4323. <dd>
  4324. <p>mysql_FieldName returns the name of the specified field.
  4325. Arguments to the function is the result identifier and the
  4326. field index. ie. <tt>mysql_FieldName($result,2);</tt> will
  4327. return the name of the second field in the result associated
  4328. with the result identifier.<br />
  4329. This function is only available if mysql support has been
  4330. enabled in PHP.</p>
  4331. </dd>
  4332. <dt><a name="mysql_fieldtype" id="mysql_fieldtype"><big>
  4333. mysql_FieldType($result,$i)</big></a></dt>
  4334. <dd>
  4335. <p>mysql_FieldType is similar to the mysql_FieldName()
  4336. function. The arguments are identical, but the field type is
  4337. returned. This will be one of "int", "char" or "real".<br />
  4338. This function is only available if mysql support has been
  4339. enabled in PHP.</p>
  4340. </dd>
  4341. <dt><a name="mysql_freeresult" id=
  4342. "mysql_freeresult"><big>mysql_FreeResult($result)</big></a></dt>
  4343. <dd>
  4344. <p>mysql_FreeResult only needs to be called if you are
  4345. worried about using too much memory while your script is
  4346. running. All result memory will automatically be freed when
  4347. the script is finished. But, if you are sure you are not
  4348. going to need the result data anymore in a script, you may
  4349. call mysql_freeresult with the result identifier as an
  4350. argument and the associated result memory will be
  4351. freed.<br />
  4352. This function is only available if mysql support has been
  4353. enabled in PHP.</p>
  4354. </dd>
  4355. <dt><a name="mysql_insert_id" id="mysql_insert_id"><big>
  4356. mysql_insert_id()</big></a></dt>
  4357. <dd>
  4358. <p>mysql_insert_id() returns the ID generated for an
  4359. AUTO_INCREMENT field. This function takes no arguments. It
  4360. will return the auto-generated ID returned by the last INSERT
  4361. query performed.</p>
  4362. </dd>
  4363. <dt><a name="mysql_listdbs" id="mysql_listdbs"><big>
  4364. $result = mysql_ListDBs()</big></a></dt>
  4365. <dd>
  4366. <p>mysql_ListDBs will return a result pointer containing the
  4367. databases available from the current mysql daemon. Use the
  4368. <a href="#mysql_dbname">mysql_dbName()</a> function to
  4369. traverse this result pointer.<br />
  4370. This function is only available if mysql support has been
  4371. enabled in PHP.</p>
  4372. </dd>
  4373. <dt><a name="mysql_listfields" id=
  4374. "mysql_listfields"><big>$result =
  4375. mysql_Listfields($database,$tablename)</big></a></dt>
  4376. <dd>
  4377. <p>mysql_listfields retrieves information about the the given
  4378. tablename. Arguments are the database name and the table
  4379. name. A result pointer is returned which can be used with
  4380. mysql_fieldflags, mysql_fieldlen, mysql_fieldname,
  4381. mysql_fieldtype. A result identifier is a positive integer.
  4382. The function returns -1 if a error occurs. A string
  4383. describing the error will be placed in $phperrmsg, and unless
  4384. the function was called as @mysql() then this error string
  4385. will also be printed out.<br />
  4386. This function is only available if mysql support has been
  4387. enabled in PHP.</p>
  4388. </dd>
  4389. <dt><a name="mysql_listtables" id=
  4390. "mysql_listtables"><big>$result =
  4391. mysql_ListTables($database)</big></a></dt>
  4392. <dd>
  4393. <p>mysql_ListTables takes a database name and result pointer
  4394. much like the <a href="#mysql">mysql()</a> function. The
  4395. <a href="#mysql_tablename">mysql_TableName()</a> function
  4396. should be used to extract the actual table names from the
  4397. result pointer.<br />
  4398. This function is only available if mysql support has been
  4399. enabled in PHP.</p>
  4400. </dd>
  4401. <dt><a name="mysql_numfields" id="mysql_numfields"><big>
  4402. mysql_NumFields($result)</big></a></dt>
  4403. <dd>
  4404. <p>mysql_NumFields returns the number of fields in a result.
  4405. The argument is the result identifier returned by the mysql()
  4406. function.<br />
  4407. This function is only available if mysql support has been
  4408. enabled in PHP.</p>
  4409. </dd>
  4410. <dt><a name="mysql_numrows" id="mysql_numrows"><big>
  4411. mysql_NumRows($result)</big></a></dt>
  4412. <dd>
  4413. <p>mysql_NumRows simply returns the number of rows in a
  4414. result. The argument is the result identifier returned by the
  4415. mysql() function.<br />
  4416. This function is only available if mysql support has been
  4417. enabled in PHP.</p>
  4418. </dd>
  4419. <dt><a name="mysql_result" id="mysql_result"><big>
  4420. mysql_Result($result,$i,field)</big></a></dt>
  4421. <dd>
  4422. <p>mysql_Result displays a field from a returned record.
  4423. Arguments are the result identifier returned by the mysql()
  4424. function, an integer which is the index of the record to be
  4425. viewed and a field name. The field argument supports the
  4426. "table.field" syntax for handling results from a join. One
  4427. difference between mSQL 1.0 and mysql is that mysql supports
  4428. functions that can act on the result data. These functions
  4429. can be applied in this function. This function is perhaps
  4430. best illustrated with a complete example:</p>
  4431. <pre>
  4432. &lt;?
  4433. $name = "bob";
  4434. $result = mysql($database,"select * from table where firstname='$name'");
  4435. $num = mysql_numrows($result);
  4436. echo "$num records found!&lt;p&gt;";
  4437. $i=0;
  4438. while($i&lt;$num);
  4439. echo mysql_result($result,$i,"lcase(fullname)");
  4440. echo "&lt;br&gt;";
  4441. echo mysql_result($result,$i,"address");
  4442. echo "&lt;br&gt;";
  4443. $i++;
  4444. endwhile;
  4445. &gt;
  4446. </pre>
  4447. <p>The above script connects to the mysql engine on the local
  4448. machine, sets the <em>name</em> variable to <em>bob</em> and
  4449. sends a query which asks for all the fields from a table
  4450. where the <em>firstname</em> field is set to <em>bob</em>. It
  4451. then displays the number of records it found after which it
  4452. loops through each of the found records and displays the
  4453. <em>fullname</em> and <em>address</em> fields for each
  4454. record. The lcase() call in the result function changes the
  4455. returned string to lower case. For a complete set of
  4456. functions that can be applied to the result data, see your
  4457. mysql documentation. As you can see, it would be trivial to
  4458. add HTML markup tags around the printed fields to format the
  4459. results in a table or in whatever manner is desired. Note
  4460. that there is no mysql_connect() call. mysql_connect need
  4461. only be called if a connection to a remote database is
  4462. desired.</p>
  4463. <p>This function is only available if mysql support has been
  4464. enabled in PHP.</p>
  4465. </dd>
  4466. <dt><a name="mysql_tablename" id="mysql_tablename"><big>
  4467. mysql_TableName($result,$i)</big></a></dt>
  4468. <dd>
  4469. <p>mysql_TableName takes a result pointer returned by the
  4470. <a href="#mysql_listtables">mysql_ListTables()</a> function
  4471. as well as an integer index and returns the name of a table.
  4472. The <a href="#mysql_numrows">mysql_NumRows()</a> function may
  4473. be used to determine the number of tables in the result
  4474. pointer. An example would be:</p>
  4475. <pre>
  4476. &lt;?
  4477. $result = mysql_listtables("dbname");
  4478. $i=0;
  4479. while($i &lt; mysql_numrows($result));
  4480. $tb_names[$i]=mysql_tablename($result, $i);
  4481. echo $tb_names[$i];
  4482. echo "&lt;BR&gt;";
  4483. $i++;
  4484. endwhile;
  4485. &gt;
  4486. </pre><br />
  4487. This function is only available if mysql support has been
  4488. enabled in PHP.
  4489. </dd>
  4490. <dt><a name="next" id="next"><big>
  4491. Next(variable)</big></a></dt>
  4492. <dd>
  4493. <p>Next moves the internal array pointer to the next item in
  4494. the array. This happens automatically when an array is
  4495. accessed using the non-indexed method ($array[]). The
  4496. function returns the value of the new item. This function can
  4497. be used to move the pointer forward without having to access
  4498. the array explicitly. One use would be to traverse an
  4499. associative array and only printing out the keys of the array
  4500. and not the actual contents.</p>
  4501. <pre>
  4502. &lt;?
  4503. Reset($array);
  4504. $i=0;
  4505. while($i &lt; count($array));
  4506. echo key($array);
  4507. next($array);
  4508. $i++;
  4509. endwhile;
  4510. &gt;
  4511. </pre>
  4512. </dd>
  4513. <dt><a name="octdec" id="octdec"><big>
  4514. OctDec(octal_number)</big></a></dt>
  4515. <dd>
  4516. <p>OctDec converts an octal number to a decimal number. See
  4517. also <a href="#decoct">DecOct()</a>.</p>
  4518. </dd>
  4519. <dt><a name="opendir" id="opendir"><big>
  4520. openDir(directory)</big></a></dt>
  4521. <dd>
  4522. <p>openDir opens the specified directory and places an
  4523. internal pointer to the beginning of the directory. Directory
  4524. entries are read using the <a href="#readdir">readDir</a>
  4525. function, and an opened directory should be closed with the
  4526. <a href="#closedir">closeDir</a> function.</p>
  4527. </dd>
  4528. <dt><a name="openlog" id="openlog"><big>
  4529. OpenLog(ident,options,facility)</big></a></dt>
  4530. <dd>
  4531. <p>OpenLog() initializes the system for further Syslog()
  4532. calls. See the openlog(3) UNIX man page for more details. See
  4533. also <a href="#initsyslog">InitSyslog()</a>, <a href=
  4534. "#syslog">Syslog()</a> and <a href=
  4535. "#closelog">CloseLog()</a>.</p>
  4536. </dd>
  4537. <dt><a name="ora_bind" id="ora_bind"><big>
  4538. Ora_Bind(cursor_ind, php_variable_name, sql_variable_name,
  4539. size)</big></a><br /></dt>
  4540. <dd>Ora_Bind() performs binding of PHP variables with Oracle
  4541. ones.<br />
  4542. <br />
  4543. Function parameters are:<br /></dd>
  4544. <dd>
  4545. <var>cursor_id</var> - oracle cursor id for _parsed_ SQL
  4546. query or PL/SQL block;<br />
  4547. <var>php_variable_name</var> - variable name in PHP script
  4548. without leading '$'<br />
  4549. <var>sql_variable_name</var> - variable name in SQL with
  4550. leading colon<br />
  4551. <var>size</var> - maximal number of bytes to be taken into
  4552. account at binding<br />
  4553. <br />
  4554. <b>Notes:</b><br />
  4555. 1) PHP variable <b>SHOULD</b> be initialised with at least
  4556. <b>size</b> bytes length string even it is return-only
  4557. variable.<br />
  4558. 2) Ora_Bind() <b>SHOULD</b> be used after Ora_Parse and
  4559. before Ora_Exec. In case of re-parsing the SQL sentence, all
  4560. used variables have to be re-bound.<br />
  4561. <br />
  4562. Ora_Bind() returns 0 upon success, -1 upon failure.<br />
  4563. <p>There is an example of Ora_Bind() usage:</p>
  4564. <pre>
  4565. /* This is the PHP variable to be bound */
  4566. $rc = "12345";
  4567. /* This is the SQL query. */
  4568. $query = "SELECT * FROM my_table where my_index = :indiana";
  4569. ........
  4570. if (Ora_Parse($cursor, $query) &lt; 0) {
  4571. echo("Parse failed!\n"
  4572. Ora_Logoff($conn);
  4573. exit;
  4574. }
  4575. if (Ora_Bind($cursor, "rc", ":indiana", strlen($rc)) &lt; 0) {
  4576. echo("Binding failed!\n"
  4577. Ora_Logoff($conn);
  4578. exit;
  4579. }
  4580. /* Execute the SQL statement associated with $cursor and
  4581. prepare storage for select-list items. */
  4582. $ncols = Ora_Exec($cursor);
  4583. ......
  4584. </pre>
  4585. </dd>
  4586. <dt><a name="ora_close" id="ora_close"><big>
  4587. Ora_Close(conn_ind)</big></a></dt>
  4588. <dd>Ora_Close() closes the Oracle connection identified by
  4589. <var>conn_ind</var>. Returns 0 upon success, -1 upon
  4590. failure.</dd>
  4591. <dt><a name="ora_commit" id="ora_commit"><big>
  4592. Ora_Commit(conn_ind)</big></a></dt>
  4593. <dd>Commits the current transaction on <var>conn_ind</var>. The
  4594. current transaction starts from the <a href=
  4595. "#ora_logon">Ora_Logon()</a> call or from the last Ora_Commit()
  4596. or <a href="#ora_rollback">Ora_Rollback()</a>, and lasts until
  4597. an Ora_Commit(), <a href="#ora_rollback">Ora_Rollback()</a> or
  4598. <a href="#ora_logoff">Ora_Logoff()</a> call is issued.
  4599. Ora_Commit() returns -1 (and an error message) upon
  4600. failure.</dd>
  4601. <dt><a name="ora_commitoff" id="ora_commitoff"><big>
  4602. Ora_CommitOff(conn_ind)</big></a></dt>
  4603. <dd>Ora_CommitOff() turns off autocommit (automatic commit of
  4604. every SQL data manipulation statement) on the Oracle connection
  4605. <var>conn_ind</var>.</dd>
  4606. <dt><a name="ora_commiton" id="ora_commiton"><big>
  4607. Ora_CommitOn(conn_ind)</big></a></dt>
  4608. <dd>Ora_CommitOff() turns on autocommit (automatic commit of
  4609. every SQL data manipulation statement) on the Oracle connection
  4610. <var>conn_ind</var>.</dd>
  4611. <dt><a name="ora_exec" id="ora_exec"><big>
  4612. Ora_Exec(cursor_ind)</big></a></dt>
  4613. <dd>Ora_Exec() executes the SQL statement associated with
  4614. <var>cursor_ind</var> and prepares storage for select-list
  4615. items. The return value is the number of columns for selects,
  4616. or -1 on error.</dd>
  4617. <dt><a name="ora_fetch" id="ora_fetch"><big>
  4618. Ora_Fetch(cursor_ind)</big></a></dt>
  4619. <dd>Ora_Fetch() retrieves a row from the database. Returns 1 if
  4620. a column was retrieved, 0 if there are no more columns to
  4621. retrieve or -1 on error.</dd>
  4622. <dt><a name="ora_getcolumn" id="ora_getcolumn"><big>
  4623. Ora_GetColumn(cursor_ind, column)</big></a></dt>
  4624. <dd>Ora_GetColumn() fetches data for a single column in a
  4625. returned row. <a href="ora_fetch">Ora_Fetch()</a> must have
  4626. been called prior to Ora_GetColumn().</dd>
  4627. <dt><a name="ora_logoff" id="ora_logoff"><big>
  4628. Ora_Logoff(conn_ind)</big></a></dt>
  4629. <dd>Ora_Logoff() disconnects the logon data area belonging to
  4630. <var>conn_ind</var> and frees used Oracle resources.</dd>
  4631. <dt><a name="ora_logon" id="ora_logon"><big>
  4632. Ora_Logon(userid, password)</big></a></dt>
  4633. <dd>Ora_Logon() establishes a connection between PHP and an
  4634. Oracle database with the given user id and password. Returns 0
  4635. on success and -1 on failure.</dd>
  4636. <dt><a name="ora_open" id="ora_open"><big>
  4637. Ora_Open(conn_ind)</big></a></dt>
  4638. <dd>Ora_Open() opens a cursor in Oracle that maintains state
  4639. information about the processing of a SQL statement. Returns a
  4640. cursor index or -1 on error.</dd>
  4641. <dt><a name="ora_parse" id="ora_parse"><big>
  4642. Ora_Parse(cursor_ind, sql_statement [,
  4643. defer])</big></a></dt>
  4644. <dd>Ora_Parse() parses a SQL statement or PL/SQL block and
  4645. associates it with a cursor. An optional third argument can be
  4646. set to 1 to defer the parse. Returns 0 on success or -1 on
  4647. error.</dd>
  4648. <dt><a name="ora_rollback" id="ora_rollback"><big>
  4649. Ora_Rollback(cursor_ind)</big></a></dt>
  4650. <dd>Ora_Rollback() rolls back the current transaction. See
  4651. <a href="#ora_commit">Ora_Commit()</a> for a definition of the
  4652. current transaction.</dd>
  4653. <dt><a name="ord" id="ord"><big>
  4654. Ord(arg)</big></a></dt>
  4655. <dd>
  4656. <p>Ord returns the ASCII value of the first character of
  4657. arg.</p>
  4658. </dd>
  4659. <dt><a name="parse_str" id="parse_str"><big>
  4660. Parse_Str(arg)</big></a></dt>
  4661. <dd>
  4662. <p>Parse_str takes a string identical to a regular URL
  4663. encoded string and extracts variables and their values.<br />
  4664. ex.</p>
  4665. <pre>
  4666. &lt;? parse_str("a[]=hello+world&amp;a[]=second+variable");
  4667. echo $a[],"&lt;br&gt;";
  4668. echo $a[],"&lt;br&gt;";
  4669. &gt;
  4670. produces
  4671. hello world
  4672. second variable
  4673. </pre>
  4674. </dd>
  4675. <dt><a name="passthru" id="passthru"><big>
  4676. PassThru(command_string [,return_var])</big></a></dt>
  4677. <dd>
  4678. <p>The PassThru() function is similar to the <a href=
  4679. "#exec">Exec()</a> function in that it executes a Unix
  4680. command. If the return_var argument is present, the return
  4681. status of the Unix command will be placed here. This command
  4682. should be used in place of Exec or System when the output
  4683. from the Unix command is binary data which needs to be passed
  4684. directly back to the browser. A common use for this is to
  4685. execute something like the pbmplus utilities that can output
  4686. an image stream directly. By setting the content-type to
  4687. <em>image/gif</em> and then calling a pbmplus program to
  4688. output a gif, you can create PHP/FI scripts that output
  4689. images directly.</p>
  4690. </dd>
  4691. <dt><a name="pclose" id="pclose"><big>
  4692. pclose(fp)</big></a></dt>
  4693. <dd>
  4694. <p>Pclose closes a pipe opened using the <a href=
  4695. "#popen">popen()</a> function.</p>
  4696. </dd>
  4697. <dt><a name="pg_close" id="pg_close"><big>
  4698. pg_Close(connection_id)</big></a></dt>
  4699. <dd>
  4700. <p>pg_Close will close down the connection to a Postgres
  4701. database associated with the given connection identifier.</p>
  4702. <p>This function is only available if Postgres support has
  4703. been enabled in PHP.</p>
  4704. </dd>
  4705. <dt><a name="pg_connect" id="pg_connect"><big>
  4706. $connection = pg_Connect(host, port, options, tty,
  4707. dbname)</big></a></dt>
  4708. <dd>
  4709. <p>pg_Connect opens a connection to a Postgres database. Each
  4710. of the arguments should be a quoted string, including the
  4711. port number. The options and tty arguments are optional and
  4712. can be empty strings. This function returns a connection_id.
  4713. This identifier is needed by other Postgres functions. You
  4714. can have multiple connections open at once. This function
  4715. will return <strong>0</strong> on error.</p>
  4716. <p>This function is only available if Postgres support has
  4717. been enabled in PHP.</p>
  4718. </dd>
  4719. <dt><a name="pg_dbname" id="pg_dbname"><big>
  4720. pg_DBname(connection_id)</big></a></dt>
  4721. <dd>
  4722. <p>pg_DBname will return the name of the database that the
  4723. given Postgres connection identifier is connected to.</p>
  4724. <p>This function is only available if Postgres support has
  4725. been enabled in PHP.</p>
  4726. </dd>
  4727. <dt><a name="pg_errorMessage" id="pg_errorMessage"><big>
  4728. pg_ErrorMessage(connection_id)</big></a></dt>
  4729. <dd>
  4730. <p>If an error occured on the last database action for which
  4731. a valid connection exists, this function will return a string
  4732. containing the error message generated by the back-end
  4733. server.</p>
  4734. <p>This function is only available if Postgres support has
  4735. been enabled in PHP.</p>
  4736. </dd>
  4737. <dt><a name="pg_exec" id="pg_exec"><big>$result =
  4738. pg_Exec(connection_id, query_string)</big></a></dt>
  4739. <dd>
  4740. <p>pg_Exec will send an SQL statement to the Postgres
  4741. database specified by the connection_id. The connection_id
  4742. must be a valid identifier that was returned by pg_Connect.
  4743. The return value of this function is an identifier to be used
  4744. to access the results from other Postgres functions. This
  4745. function will return <strong>0</strong> on error. It will
  4746. return <strong>1</strong> when the command executed correctly
  4747. but are not expected to returned data (insert or update
  4748. commands, for example). Note that selects which return no
  4749. data will still return a valid result greater than 1.</p>
  4750. <p>This function is only available if Postgres support has
  4751. been enabled in PHP.</p>
  4752. </dd>
  4753. <dt><a name="pg_fieldname" id="pg_fieldname"><big>
  4754. pg_FieldName(result_id, field_number)</big></a></dt>
  4755. <dd>
  4756. <p>pg_FieldName will return the name of the field occupying
  4757. the given column number in the given Postgres result
  4758. identifier. Field numbering starts from 0.</p>
  4759. <p>This function is only available if Postgres support has
  4760. been enabled in PHP.</p>
  4761. </dd>
  4762. <dt><a name="pg_fieldprtlen" id="pg_fieldprtlen"><big>
  4763. pg_FieldPrtLen(result_id, row_number,
  4764. field_name)</big></a></dt>
  4765. <dd>
  4766. <p>pg_FieldPrtLen will return the actual printed length
  4767. (number of characters) of a specific value in a Postgres
  4768. result. Row numbering starts at 0. This function will return
  4769. <strong>-1</strong> on an error.</p>
  4770. <p>This function is only available if Postgres support has
  4771. been enabled in PHP.</p>
  4772. </dd>
  4773. <dt><a name="pg_fieldnum" id="pg_fieldnum"><big>
  4774. pg_FieldNum(result_id, field_name)</big></a></dt>
  4775. <dd>
  4776. <p>pg_FieldNum will return the number of the column slot that
  4777. corresponds to the named field in the given Postgres result
  4778. identifier. Field numbering starts at 0. This function will
  4779. return <strong>-1</strong> on error.</p>
  4780. <p>This function is only available if Postgres support has
  4781. been enabled in PHP.</p>
  4782. </dd>
  4783. <dt><a name="pg_fieldsize" id="pg_fieldsize"><big>
  4784. pg_FieldSize(result_id, field_name)</big></a></dt>
  4785. <dd>
  4786. <p>pg_FieldSize will return the internal storage size (in
  4787. bytes) of the named field in the given Postgres result. A
  4788. field size of 0 indicates a variable length field. This
  4789. function will return <strong>-1</strong> on error.</p>
  4790. <p>This function is only available if Postgres support has
  4791. been enabled in PHP.</p>
  4792. </dd>
  4793. <dt><a name="pg_fieldtype" id="pg_fieldtype"><big>
  4794. pg_FieldType(result_id, field_number)</big></a></dt>
  4795. <dd>
  4796. <p>pg_FieldType will return a string containing the type name
  4797. of the given field in the given Postgres result identifier.
  4798. Field numbering starts at 0.</p>
  4799. <p>This function is only available if Postgres support has
  4800. been enabled in PHP.</p>
  4801. </dd>
  4802. <dt><a name="pg_freeresult" id="pg_freeresult"><big>
  4803. pg_FreeResult(result_id)</big></a></dt>
  4804. <dd>
  4805. <p>pg_FreeResult only needs to be called if you are worried
  4806. about using too much memory while your script is running. All
  4807. result memory will automatically be freed when the script is
  4808. finished. But, if you are sure you are not going to need the
  4809. result data anymore in a script, you may call pg_freeresult
  4810. with the result identifier as an argument and the associated
  4811. result memory will be freed.</p>
  4812. <p>This function is only available if Postgres support has
  4813. been enabled in PHP.</p>
  4814. </dd>
  4815. <dt><a name="pg_getlastoid" id="pg_getlastoid"><big>
  4816. pg_GetLastOid()</big></a></dt>
  4817. <dd>
  4818. <p>pg_GetLastOid can be used to retrieve the Oid assigned to
  4819. an inserted tuple if the last command sent via pg_Exec was an
  4820. SQL Insert. This function will return a positive integer if
  4821. there was a valid Oid. It will return <strong>-1</strong> if
  4822. an error occured or the last command sent via pg_Exec was not
  4823. an Insert.</p>
  4824. <p>This function is only available if Postgres support has
  4825. been enabled in PHP.</p>
  4826. </dd>
  4827. <dt><a name="pg_host" id="pg_host"><big>
  4828. pg_Host(connection_id)</big></a></dt>
  4829. <dd>
  4830. <p>pg_Host will return the host name the the given Postgres
  4831. connection identifier is connected to.</p>
  4832. <p>This function is only available if Postgres support has
  4833. been enabled in PHP.</p>
  4834. </dd>
  4835. <dt><a name="pg_numfields" id="pg_numfields"><big>
  4836. pg_NumFields(result_id)</big></a></dt>
  4837. <dd>
  4838. <p>pg_NumFields will return the number of fields (columns) in
  4839. a Postgres result. The argument is a valid result identifier
  4840. returned by pg_Exec. This function will return
  4841. <strong>-1</strong> on error.</p>
  4842. <p>This function is only available if Postgres support has
  4843. been enabled in PHP.</p>
  4844. </dd>
  4845. <dt><a name="pg_numrows" id="pg_numrows"><big>
  4846. pg_NumRows(result_id)</big></a></dt>
  4847. <dd>
  4848. <p>pg_NumRows will return the number of rows in a Postgres
  4849. result. The argument is a valid result identifier returned by
  4850. pg_Exec. This function will return <strong>-1</strong> on
  4851. error.</p>
  4852. <p>This function is only available if Postgres support has
  4853. been enabled in PHP.</p>
  4854. </dd>
  4855. <dt><a name="pg_options" id="pg_options"><big>
  4856. pg_Options(connection_id)</big></a></dt>
  4857. <dd>
  4858. <p>pg_Options will return a string containing the options
  4859. specified on the given Postgres connection identifier.</p>
  4860. <p>This function is only available if Postgres support has
  4861. been enabled in PHP.</p>
  4862. </dd>
  4863. <dt><a name="pg_port" id="pg_port"><big>
  4864. pg_Port(connection_id)</big></a></dt>
  4865. <dd>
  4866. <p>pg_Port will return the port number that the given
  4867. Postgres connection identifier is connected to.</p>
  4868. <p>This function is only available if Postgres support has
  4869. been enabled in PHP.</p>
  4870. </dd>
  4871. <dt><a name="pg_result" id="pg_result"><big>
  4872. pg_Result(result_id, row_number, field
  4873. name/index)</big></a></dt>
  4874. <dd>
  4875. <p>pg_Result will return values from a result identifier
  4876. produced by pg_Exec. The row_number and field name specify
  4877. what cell in the table of results to return. Row numbering
  4878. starts from 0. Instead of naming the field, you may use the
  4879. field index as an unquoted number. Field indices start from
  4880. 0.</p>
  4881. <p>Postgres has many built in types and only the basic ones
  4882. are directly supported here. All forms of integer, boolean
  4883. and oid types are returned as integer values. All forms of
  4884. float, and real types are returned as double values. All
  4885. other types, including arrays are returned as strings
  4886. formatted in the same default Postgres manner that you would
  4887. see in the 'monitor' or 'psql' programs.</p>
  4888. <p>Support for returning PHP arrays of numerical and string
  4889. data from a Postgres result is planned for a later date.</p>
  4890. <p>This function is only available if Postgres support has
  4891. been enabled in PHP.</p>
  4892. </dd>
  4893. <dt><a name="pg_tty" id="pg_tty"><big>
  4894. pg_tty(connection_id)</big></a></dt>
  4895. <dd>
  4896. <p>pg_tty will return the tty name that server side debugging
  4897. output is sent to on the given Postgres connection
  4898. identifier.</p>
  4899. <p>This function is only available if Postgres support has
  4900. been enabled in PHP.</p>
  4901. </dd>
  4902. <dt><a name="phpinfo" id="phpinfo"><big>
  4903. phpInfo()</big></a></dt>
  4904. <dd>
  4905. <p>phpInfo prints the same page you get when adding "?info"
  4906. to a PHP/FI parsed URL or when you run the php.cgi binary by
  4907. itself. It is especially useful for debugging scripts in the
  4908. Apache module version since it displays a number of useful
  4909. internal data.</p>
  4910. </dd>
  4911. <dt><a name="phpversion" id="phpversion"><big>
  4912. phpVersion()</big></a></dt>
  4913. <dd>
  4914. <p>phpVersion returns the version number of PHP/FI currently
  4915. running.</p>
  4916. </dd>
  4917. <dt><a name="popen" id="popen"><big>fp =
  4918. popen(command,mode)</big></a></dt>
  4919. <dd>
  4920. <p>Popen opens a pipe to a command and returns a file pointer
  4921. index. This file pointer index can be used by <a href=
  4922. "#fgets">fgets</a>, <a href="#fputs">fputs</a> and <a href=
  4923. "#fclose">fclose</a>. Arguments are the command to run and
  4924. the mode. The mode can be either "r" for read or "w" for
  4925. write. See the UNIX C library popen man page for more
  4926. details. Any file opened with popen() should be closed using
  4927. the <a href="#pclose">pclose()</a> function.</p>
  4928. </dd>
  4929. <dt><a name="pos" id="pos"><big>
  4930. pos(var)</big></a></dt>
  4931. <dd>
  4932. <p>The Pos() function returns the numerical position of an
  4933. array element within that array. This is not very useful for
  4934. normal arrays, but for associative arrays it can be
  4935. handy.</p>
  4936. </dd>
  4937. <dt><a name="pow" id="pow"><big>
  4938. pow(x,y)</big></a></dt>
  4939. <dd>
  4940. <p>Evaluates x raised to the power of y. See also <a href=
  4941. "#exp">Exp()</a></p>
  4942. </dd>
  4943. <dt><a name="prev" id="prev"><big>
  4944. Prev(variable)</big></a></dt>
  4945. <dd>
  4946. <p>Prev moves the internal array pointer for the given
  4947. variable to the previous item in the array. If already at the
  4948. beginning of the list, the pointer will point to the first
  4949. item. The function returns the value of the new item. This
  4950. function is useful for traversing an associative array in
  4951. reverse order. See the example in the <a href=
  4952. "#end">End()</a> definition. Also see <a href=
  4953. "#next">Next()</a>.</p>
  4954. </dd>
  4955. <dt><a name="putenv" id="putenv"><big>
  4956. PutEnv(string)</big></a></dt>
  4957. <dd>
  4958. <p>PutEnv puts the given string in the environment. Not
  4959. extremely useful since the local environment variables are
  4960. wiped out when PHP is done with a page, but in some cases it
  4961. is useful if other things called from within a PHP script
  4962. checks environment variables. For example, if you want to run
  4963. multiple mSQL daemon processes, you will need to use PutEnv
  4964. to switch back and forth between the different sockets.</p>
  4965. </dd>
  4966. <dt><a name="quotemeta" id="quotemeta"><big>
  4967. QuoteMeta(arg)</big></a></dt>
  4968. <dd>
  4969. <p>QuoteMeta returns a string composed of arg with any
  4970. regular expression special characters escaped with a
  4971. backslash.</p>
  4972. </dd>
  4973. <dt><a name="rand" id="rand"><big>
  4974. Rand()</big></a></dt>
  4975. <dd>
  4976. <p>Rand returns a random number between 0 and RANDMAX.
  4977. <b>Remember</b> to seed your random number generator with a
  4978. call to <a href="#srand">srand()</a> before calling rand().
  4979. You only need to seed the random number generator once.
  4980. RANDMAX can be determined with the <a href=
  4981. "#getrandmax">getRandMax</a> function. Normally a specific
  4982. range is chosen by simply using the modulus operator on the
  4983. result.</p>
  4984. </dd>
  4985. <dt><a name="readdir" id="readdir"><big>
  4986. readDir()</big></a></dt>
  4987. <dd>
  4988. <p>readDir reads the next entry from the currently open
  4989. directory structure. Once an entry is read, the pointer is
  4990. advanced to the next entry in the directory and the next call
  4991. to this function will return the next entry in the directory.
  4992. Use the <a href="#opendir">openDir</a> function to open a
  4993. directory before calling this function.</p>
  4994. </dd>
  4995. <dt><a name="readfile" id="readfile"><big>
  4996. ReadFile(filename)</big></a></dt>
  4997. <dd>
  4998. <p>$size = ReadFile(Filename) - Reads the file filename and
  4999. simply outputs it directly. It returns the number of bytes
  5000. actually read. It is different from the File() command in
  5001. that it does not store the file in memory, and it is safe for
  5002. use on binary files. This function is generally used where
  5003. one might otherwise do a PassThru("cat filename"). Using
  5004. ReadFile is more efficient.</p>
  5005. </dd>
  5006. <dt><a name="readlink" id="readlink"><big>
  5007. ReadLink(path)</big></a></dt>
  5008. <dd>ReadLink does the same as the readlink C function and
  5009. returns the contents of the symbolic link path or -1 in case of
  5010. error. See also <a href="#linkinfo">LinkInfo</a>.</dd>
  5011. <dt><a name="reg_match" id="reg_match"><big>
  5012. reg_Match(expr,arg[,regs])</big></a></dt>
  5013. <dd>
  5014. <p><b>This function has been replaced by the <a href=
  5015. "#ereg">ereg()</a> function. It is however still available
  5016. for backwards compatibility.</b><br />
  5017. reg_Match returns non-zero if the regular expression is
  5018. matched in the argument string. For example, the condition,
  5019. <tt>&lt;?if (reg_match("^This.*", "This is an example
  5020. string")&gt;</tt> would be true since the "^This.*"
  5021. expression says to match the word <strong>This</strong> at
  5022. the beginning of the string and then match any characters
  5023. afterwards. If the <em>regs</em> argument is present, then
  5024. match registers are filled into positions 0-10 in the array
  5025. named by the <em>regs</em> argument. Register 0 will always
  5026. contain the full matched string. For more information on
  5027. regular expressions, see the <a href="#regexp">regular
  5028. expression section</a> of this document.</p>
  5029. </dd>
  5030. <dt><a name="reg_replace" id="reg_replace"><big>
  5031. reg_replace(expr,replace,arg)</big></a></dt>
  5032. <dd>
  5033. <p><b>This function has been replaced by the <a href=
  5034. "#ereg_replace">ereg_replace()</a> function. It is however
  5035. still available for backwards compatibility.</b><br />
  5036. reg_Replace scans the entire argument string and replaces any
  5037. portions of the string matched by the given expression with
  5038. the replacement string. For example, in the string, <tt>"This
  5039. is an example string"</tt> we could very easily replace every
  5040. space with a dash with the command: <strong>reg_replace("
  5041. ","-","This is an example string")</strong>.For more
  5042. information on regular expressions, see the <a href=
  5043. "#regexp">regular expression section</a> of this
  5044. document.</p>
  5045. </dd>
  5046. <dt><a name="reg_search" id="reg_search"><big>
  5047. reg_Search(expr,arg[,regs])</big></a></dt>
  5048. <dd>
  5049. <p><b>This function has been replaced by the <a href=
  5050. "#ereg">ereg()</a> function. It is however still available
  5051. for backwards compatibility.</b><br />
  5052. reg_Search will scan the entire argument string for any
  5053. matches to the given regular expression. If a match is found,
  5054. it will return the portion of the string starting at where
  5055. the match occurred. If no match is found a zero-length string
  5056. is returned. If the <em>regs</em> argument is present, then
  5057. match registers are filled into positions 0-10 in the array
  5058. named by the <em>regs</em> argument. Register 0 will always
  5059. be assigned the full matched string. For more information on
  5060. regular expressions, see the <a href="#regexp">regular
  5061. expression section</a> of this document.</p>
  5062. </dd>
  5063. <dt><a name="rename" id="rename"><big>
  5064. Rename(old,new)</big></a></dt>
  5065. <dd>
  5066. <p>Rename filename old to new. Similar to the Unix C rename()
  5067. function.</p>
  5068. </dd>
  5069. <dt><a name="reset" id="reset"><big>
  5070. Reset(variable)</big></a></dt>
  5071. <dd>
  5072. <p>Reset moves the internal array pointer for the given array
  5073. variable to the first item of the array and returns the value
  5074. of this item. This is useful for traversing associative and
  5075. non-indexed arrays. See also <a href="#end">End()</a> and
  5076. <a href="#next">Next()</a>. The following example traverses
  5077. an associative array:</p>
  5078. <pre>
  5079. &lt;?
  5080. Reset($array);
  5081. $i=0;
  5082. while($i &lt; count($array));
  5083. echo $array[]; /* pointer automatically moves ahead one */
  5084. $i++;
  5085. endwhile;
  5086. &gt;
  5087. </pre>
  5088. </dd>
  5089. <dt><a name="return" id="return"><big>
  5090. return(value)</big></a></dt>
  5091. <dd>
  5092. <p>Return exits the current function call and returns the
  5093. specified value back to the caller. See the section on
  5094. <a href="#user_funcs">User-Defined Functions</a> for more
  5095. information.</p>
  5096. </dd>
  5097. <dt><a name="rewind" id="rewind"><big>
  5098. rewind($fd)</big></a></dt>
  5099. <dd>
  5100. <p>rewind() resets a file pointer identified by the $fd
  5101. argument which is the return value of the <a href=
  5102. "#fopen">fopen()</a> call. The file pointer is positioned at
  5103. the beginning of the file. See also <a href=
  5104. "#ftell">ftell()</a> and <a href="#fseek">fseek()</a>.</p>
  5105. </dd>
  5106. <dt><a name="rewinddir" id="rewinddir"><big>
  5107. rewindDir()</big></a></dt>
  5108. <dd>
  5109. <p>rewindDir moves the current directory pointer back to the
  5110. beginning of the directory. Use the <a href=
  5111. "#opendir">openDir</a> function to open a directory before
  5112. calling this function.</p>
  5113. </dd>
  5114. <dt><a name="rmdir" id="rmdir"><big>
  5115. RmDir(dir)</big></a></dt>
  5116. <dd>
  5117. <p>RmDir() removes the given directory. See the <a href=
  5118. "#unlink">Unlink()</a> function for removing regular
  5119. files.</p>
  5120. </dd>
  5121. <dt><a name="setcookie" id="setcookie"><big>
  5122. SetCookie(name,value,expire,path,domain,secure)</big></a></dt>
  5123. <dd>
  5124. <p>SetCookie() defines a cookie to be sent along with the
  5125. rest of the header information. All the arguments except the
  5126. name argument are optional. If only the name argument is
  5127. present, the cookie by that name will be deleted from the
  5128. remote client. You may also replace any argument with an
  5129. empty string (<b>""</b>) in order to skip that argument. The
  5130. expire and secure arguments are integers and cannot be
  5131. skipped with an empty string. Use a zero (<b>0</b>) instead.
  5132. The expire argument is a regular Unix time integer as
  5133. returned by the <a href="#time">time()</a> or <a href=
  5134. "#mktime">mktime()</a> functions. Some examples follow:</p>
  5135. <pre>
  5136. SetCookie("TestCookie","Test Value");
  5137. SetCookie("TestCookie",$value,time()+3600); /* expire in 1 hour */
  5138. SetCookie("TestCookie",$value,time()+3600,"/~rasmus/",".utoronto.ca",1);
  5139. </pre>
  5140. <p>Note that the value portion of the cookie will
  5141. automatically be urlencoded when you send the cookie, and
  5142. when it is received, it is automatically decoded and assigned
  5143. to a variable by the same name as the cookie name. ie. to see
  5144. the contents of our test cookie in a script, simply do:</p>
  5145. <pre>
  5146. echo $TestCookie;
  5147. </pre>
  5148. </dd>
  5149. <dt><a name="seterrorreporting" id=
  5150. "seterrorreporting"><big>
  5151. SetErrorReporting(arg)</big></a></dt>
  5152. <dd>
  5153. <p>SetErrorReporting sets the current error reporting state
  5154. to the value of <em>arg</em>. If non-zero, errors will be
  5155. printed, and if 0 they won't be. The function returns the
  5156. previous error reporting state. This is a more general way of
  5157. disabling error reporting than by preceding individual
  5158. functions with a '@' character. See the section on <a href=
  5159. "#quiet">Suppressing Errors from function calls</a> for more
  5160. information.</p>
  5161. </dd>
  5162. <dt><a name="setlogging" id="setlogging"><big>
  5163. SetLogging(arg)</big></a></dt>
  5164. <dd>
  5165. <p>SetLogging() either enables or disables the logging of
  5166. access statistics for a page. If <em>arg</em> is non-zero,
  5167. logging will be enabled, if zero, disabled.</p>
  5168. </dd>
  5169. <dt><a name="setshowinfo" id="setshowinfo"><big>
  5170. SetShowInfo(arg)</big></a></dt>
  5171. <dd>
  5172. <p>SetShowInfo() either enables or disables the information
  5173. footer at the bottom of all pages loaded through PHP. If
  5174. <em>arg</em> is non-zero, the footers will be enabled, if
  5175. zero, disabled.</p>
  5176. </dd>
  5177. <dt><a name="settype" id="settype"><big>
  5178. SetType(variable,type)</big></a></dt>
  5179. <dd>
  5180. <p>SetType sets the type of a variable. The type argument is
  5181. one of, "integer", "double" or "string". See also the
  5182. <a href="#gettype">GetType()</a> function.</p>
  5183. </dd>
  5184. <dt><a name="shl" id="shl"><big>
  5185. shl(n,b)</big></a></dt>
  5186. <dd>
  5187. <p>Shift the value <b>n</b> left <b>b</b> bits.</p>
  5188. </dd>
  5189. <dt><a name="shr" id="shr"><big>
  5190. shr(n,b)</big></a></dt>
  5191. <dd>
  5192. <p>Shift the value <b>n</b> right <b>b</b> bits.</p>
  5193. </dd>
  5194. <dt><a name="sin" id="sin"><big>
  5195. Sin(arg)</big></a></dt>
  5196. <dd>
  5197. <p>Sin returns the sine of arg in radians. See also <a href=
  5198. "#cos">Cos()</a> and <a href="#tan">Tan()</a></p>
  5199. </dd>
  5200. <dt><a name="sleep" id="sleep"><big>
  5201. Sleep(secs)</big></a></dt>
  5202. <dd>
  5203. <p>Sleep will delay for secs seconds. Similar to the Unix C
  5204. sleep() function. See also the <a href="#usleep">USleep()</a>
  5205. function.</p>
  5206. </dd>
  5207. <dt><a name="solid_close" id="solid_close"><big>
  5208. Solid_Close(connection_id)</big></a></dt>
  5209. <dd>
  5210. <p>Solid_Close will close down the connection to the Solid
  5211. server associated with the given connection identifier.</p>
  5212. <p>This function is only available if Solid support has been
  5213. enabled in PHP.</p>
  5214. </dd>
  5215. <dt><a name="solid_connect" id="solid_connect"><big>
  5216. $connection = Solid_Connect(data source name, username,
  5217. password)</big></a></dt>
  5218. <dd>
  5219. <p>Solid_Connect opens a connection to a Solid server. Each
  5220. of the arguments should be a quoted string. The first
  5221. parameter (data source name) can be an empty string,
  5222. resulting in a connection to the default server on the
  5223. localhost. This function returns a connection_id. This
  5224. identifier is needed by other Solid functions. You can have
  5225. multiple connections open at once. This function will return
  5226. <strong>0</strong> on error.</p>
  5227. <p>This function is only available if Solid support has been
  5228. enabled in PHP.</p>
  5229. </dd>
  5230. <dt><a name="solid_exec" id="solid_exec"><big>
  5231. $result = Solid_Exec(connection_id,
  5232. query_string)</big></a></dt>
  5233. <dd>
  5234. <p>Solid_Exec will send an SQL statement to the Solid server
  5235. specified by the connection_id. The connection_id must be a
  5236. valid identifier that was returned by Solid_Connect. The
  5237. return value of this function is an identifier to be used to
  5238. access the results by other Solid functions. This function
  5239. will return <strong>0</strong> on error. It will return
  5240. <strong>1</strong> when the command executed correctly but
  5241. are not expected to returned data (insert or update commands,
  5242. for example). Note that selects which return no data will
  5243. still return a valid result greater than 1.</p>
  5244. <p>This function is only available if Solid support has been
  5245. enabled in PHP.</p>
  5246. </dd>
  5247. <dt><a name="solid_fetchrow" id="solid_fetchrow"><big>
  5248. Solid_FetchRow(result_id)</big></a></dt>
  5249. <dd>
  5250. <p>Solid_FetchRow fetches a row of the data that was returned
  5251. by Solid_Exec. After Solid_FetchRow is called, the fields of
  5252. that row can be access with Solid_Result. Every time
  5253. Solid_FetchRow is called a new row can be accessed by
  5254. Solid_Result. If Solid_FetchRow was succesful (there was a
  5255. new row), <strong>1</strong> is returned, if there are no
  5256. more rows, Solid_FetchRow will return <strong>0</strong>. The
  5257. return value of Solid_FetchRow can be used as the condition
  5258. of a while loop.</p>
  5259. <p>This function is only available if Solid support has been
  5260. enabled in PHP.</p>
  5261. </dd>
  5262. <dt><a name="solid_fieldname" id="solid_fieldname"><big>
  5263. Solid_FieldName(result_id, field_number)</big></a></dt>
  5264. <dd>
  5265. <p>Solid_FieldName will return the name of the field
  5266. occupying the given column number in the given Solid result
  5267. identifier. Field numbering starts from 0.</p>
  5268. <p>This function is only available if Solid support has been
  5269. enabled in PHP.</p>
  5270. </dd>
  5271. <dt><a name="solid_fieldnum" id="solid_fieldnum"><big>
  5272. Solid_FieldNum(result_id, field_name)</big></a></dt>
  5273. <dd>
  5274. <p>Solid_FieldNum will return the number of the column slot
  5275. that corresponds to the named field in the given Solid result
  5276. identifier. Field numbering starts at 0. This function will
  5277. return <strong>-1</strong> on error.</p>
  5278. <p>This function is only available if Solid support has been
  5279. enabled in PHP.</p>
  5280. </dd>
  5281. <dt><a name="solid_freeresult" id=
  5282. "solid_freeresult"><big>Solid_FreeResult(result_id)</big></a></dt>
  5283. <dd>
  5284. <p>Solid_FreeResult only needs to be called if you are
  5285. worried about using too much memory while your script is
  5286. running. All result memory will automatically be freed when
  5287. the script is finished. But, if you are sure you are not
  5288. going to need the result data anymore in a script, you may
  5289. call Solid_FreeResult with the result identifier as an
  5290. argument and the associated result memory will be freed.</p>
  5291. <p>This function is only available if Solid support has been
  5292. enabled in PHP.</p>
  5293. </dd>
  5294. <dt><a name="solid_numfields" id="solid_numfields"><big>
  5295. Solid_NumFields(result_id)</big></a></dt>
  5296. <dd>
  5297. <p>Solid_NumFields will return the number of fields (columns)
  5298. in a Solid result. The argument is a valid result identifier
  5299. returned by Solid_Exec. This function will return
  5300. <strong>-1</strong> on error.</p>
  5301. <p>This function is only available if Solid support has been
  5302. enabled in PHP.</p>
  5303. </dd>
  5304. <dt><a name="solid_numrows" id="solid_numrows"><big>
  5305. Solid_NumRows(result_id)</big></a></dt>
  5306. <dd>
  5307. <p>Solid_NumRows will return the number of rows in a Solid
  5308. result. The argument is a valid result identifier returned by
  5309. Solid_Exec. This function will return <strong>-1</strong> on
  5310. error. <b>Large Caveat:</b> The SOLID SQL server uses ODBC as
  5311. it's primary (and only) interface. SolidNumRows() uses
  5312. SQLRowCount at the low-level to get the number of rows.
  5313. SQLRowCount follows the age-old Microsoft tradition of
  5314. unnecessary limitations, strange exceptions and other odd
  5315. things. This means that the function will only return the
  5316. number of rows affected by an INSERT, UPDATE or a DELETE
  5317. clause. No SELECT! As a workaround you can try the count()
  5318. statement of SQL or a while-loop that counts the number of
  5319. rows. If you need Solid_NumRows() to figure out how many
  5320. records to read after a SELECT clause, try checking the
  5321. return value from <a href=
  5322. "#solid_fetchrow">Solid_FetchRow()</a> instead. So instead
  5323. of:</p>
  5324. <pre>
  5325. $num = Solid_NumRows();
  5326. $i=0;
  5327. while ($i &lt; $num) {
  5328. /* print results... */
  5329. $i++;
  5330. }
  5331. </pre>
  5332. <p>you might try:</p>
  5333. <pre>
  5334. while(Solid_FetchRow($result)) {
  5335. /* print results... */
  5336. }
  5337. </pre>
  5338. <p>This function is only available if Solid support has been
  5339. enabled in PHP.</p>
  5340. </dd>
  5341. <dt><a name="solid_result" id="solid_result"><big>
  5342. Solid_Result(result_id, field name/index)</big></a></dt>
  5343. <dd>
  5344. <p>Solid_Result will return values from a result identifier
  5345. produced by Solid_Exec. The field name specify what cell in
  5346. the row to return. Instead of naming the field, you may use
  5347. the field index as an unquoted number. Field indices start
  5348. from 0.</p>
  5349. <p>This function is only available if Solid support has been
  5350. enabled in PHP.</p>
  5351. </dd>
  5352. <dt><a name="sort" id="sort"><big>
  5353. Sort(array)</big></a></dt>
  5354. <dd>
  5355. <p>Sort is used to sort a PHP array in ascending order. To
  5356. sort in descending order, use the RSort() function. It
  5357. understands the three variable types and will sort
  5358. alphabetically if the array contains strings, and numerically
  5359. if the array contains numbers. In the case of an array which
  5360. contains a mixture of types, the first type in the array will
  5361. specify the sort method. Note that if you are going to sort
  5362. an associative array, you should use the <a href=
  5363. "#asort">ASort()</a> function.</p>
  5364. </dd>
  5365. <dt><a name="soundex" id="soundex"><big>
  5366. Soundex(string)</big></a></dt>
  5367. <dd>
  5368. <p>This function takes a string argument and returns the
  5369. soundex key for the string. Soundex keys have the property
  5370. that words pronounced similarly produce the same soundex key,
  5371. and can thus be used to simplify searches in databases where
  5372. you know the pronunciation but not the spelling. This soundex
  5373. function returns a string 4 characters long, starting with a
  5374. letter.<br />
  5375. This particular soundex function is one described by Donald
  5376. Knuth in "The Art Of Computer Programming, vol. 3: Sorting
  5377. And Searching", Addison-Wesley (1973), pp. 391-392.<br />
  5378. Example:</p>
  5379. <pre>
  5380. Euler and Ellery map to E460
  5381. Gauss and Ghosh map to G200
  5382. Hilbert and Heilbronn map to H416
  5383. Knuth and Kant map to K530
  5384. Lloyd and Ladd map to L300
  5385. Lukasiewicz and Lissajous map to L222
  5386. </pre>
  5387. </dd>
  5388. <dt><a name="sprintf" id="sprintf"><big>
  5389. Sprintf(format,arg [,arg,arg,arg,arg])</big></a></dt>
  5390. <dd>
  5391. <p>Sprintf returns the string created by the formatted output
  5392. defined by the format argument and arg. It is similar to the
  5393. formatted version of the <a href="#echo">echo</a> command,
  5394. except this just returns the string while echo displays it.
  5395. It is also similar to the C function by the same name. The
  5396. difference being that this version does not accept more than
  5397. 5 <em>arg</em> arguments. If you need to format more than 5
  5398. arguments into a single string, simply call sprintf()
  5399. multiple times for each group of arguments. Note that the
  5400. type of the argument doesn't affect the output. The argument
  5401. type is automagically converted to match the type specified
  5402. in the format string.</p>
  5403. </dd>
  5404. <dt><a name="sqrt" id="sqrt"><big>
  5405. Sqrt(arg)</big></a></dt>
  5406. <dd>
  5407. <p>Sqrt returns the square root of arg.</p>
  5408. </dd>
  5409. <dt><a name="srand" id="srand"><big>
  5410. Srand(integer)</big></a></dt>
  5411. <dd>
  5412. <p>Srand seeds the random number generator. This function
  5413. takes any integer as an argument. One choice for a seed value
  5414. is to use the <strong>date</strong> function to give you the
  5415. current number of seconds past the minute. Note that this
  5416. function <b>does not return a value</b>! This function simply
  5417. seeds the random number generator for subsequent calls to the
  5418. <a href="#rand">rand()</a> function. eg.</p>
  5419. <pre>
  5420. &lt;?srand(date("s"))&gt;
  5421. </pre>
  5422. </dd>
  5423. <dt><a name="strchr" id="strchr"><big>
  5424. strchr(string,arg)</big></a></dt>
  5425. <dd>
  5426. <p>strchr and <a href="#strstr">strstr</a> are actually
  5427. identical functions. They can be used interchangeably and
  5428. both are included for completeness sake. They will return the
  5429. portion of the string argument starting at the point where
  5430. the given sub-string is found. For example, in the string,
  5431. "This is an example string" above, the call: <tt>&lt;?echo
  5432. strchr($string,"an ")&gt;</tt> would return the string:
  5433. <tt>"an example string"</tt>.</p>
  5434. </dd>
  5435. <dt><a name="strtr" id="strtr"><big>
  5436. strtr(input,set1,set2)</big></a></dt>
  5437. <dd>strtr() translates each character of "string" that is in
  5438. "set1" to the corresponding character in "set2". Characters not
  5439. in set1 are passed through unchanged. When a character appears
  5440. more than once in "set1" and the corresponding characters in
  5441. "set2" are not all the same, only the final one is used. When
  5442. one of "set1" or "set2" is longer, longer "set?" is truncated
  5443. to length of shorter "set?".</dd>
  5444. <dt><a name="stripslashes" id="stripslashes"><big>
  5445. StripSlashes(arg)</big></a></dt>
  5446. <dd>
  5447. <p>StripSlashes unescapes the string argument. See also
  5448. <a href="#addslashes">AddSlashes()</a>.</p>
  5449. </dd>
  5450. <dt><a name="strlen" id="strlen"><big>
  5451. strlen(string)</big></a></dt>
  5452. <dd>
  5453. <p>strlen returns the length of the string.</p>
  5454. </dd>
  5455. <dt><a name="strrchr" id="strrchr"><big>
  5456. strrchr(string,arg)</big></a></dt>
  5457. <dd>
  5458. <p>strrchr will search for a single character starting at the
  5459. end of the argument string and working its way backwards. It
  5460. returns the string starting with the search character if the
  5461. character was found and an empty string if it wasn't.</p>
  5462. </dd>
  5463. <dt><a name="strstr" id="strstr"><big>
  5464. strstr(string,arg)</big></a></dt>
  5465. <dd>
  5466. <p>strstr and <a href="#strchr">strchr</a> are actually
  5467. identical functions. They can be used interchangeably and
  5468. both are included for completeness sake. They will return the
  5469. portion of the string argument starting at the point where
  5470. the given sub-string is found. For example, in the string,
  5471. "This is an example string" above, the call: <tt>&lt;?echo
  5472. strstr($string,"an ")&gt;</tt> would return the string:
  5473. <tt>"an example string"</tt>.</p>
  5474. </dd>
  5475. <dt><a name="strtok" id="strtok"><big>
  5476. strtok(string,arg)</big></a></dt>
  5477. <dd>
  5478. <p>strtok is used to tokenize a string. That is, if you have
  5479. a string like <strong>"This is an example string"</strong>
  5480. you could tokenize this string into its individual words by
  5481. using the space character as the token. You would use the
  5482. following script code:</p>
  5483. <pre>
  5484. &lt;?
  5485. $string = "This is an example string";
  5486. $tok = strtok($string," ");
  5487. while($tok);
  5488. echo "Word=$tok&lt;br&gt;";
  5489. $tok = strtok(" ");
  5490. endwhile;
  5491. &gt;
  5492. </pre>
  5493. <p>Note that only the first call to strtok uses the string
  5494. argument. Every subsequent call to strtok only needs the
  5495. token to use, as it keeps track of where it is in the current
  5496. string. To start over, or to tokenize a new string you simply
  5497. call strtok with the string argument again to initialize it.
  5498. Note that you may put multiple tokens in the <i>arg</i>
  5499. parameter. The string will be tokenized when any one of the
  5500. characters in the argument are found.</p>
  5501. </dd>
  5502. <dt><a name="strtolower" id="strtolower"><big>
  5503. strtolower(string)</big></a></dt>
  5504. <dd>
  5505. <p>strtolower converts the string argument to all lower case
  5506. characters.</p>
  5507. </dd>
  5508. <dt><a name="strtoupper" id="strtoupper"><big>
  5509. strtoupper(string)</big></a></dt>
  5510. <dd>
  5511. <p>strtoupper converts the string argument to all upper case
  5512. characters.</p>
  5513. </dd>
  5514. <dt><a name="strval" id="strval"><big>
  5515. strval(variable)</big></a></dt>
  5516. <dd>
  5517. <p>strval returns the string value of the variable. See also
  5518. the <a href="#intval">intval()</a> and <a href=
  5519. "#doubleval">doubleval()</a> functions.</p>
  5520. </dd>
  5521. <dt><a name="substr" id="substr"><big>substr(string,
  5522. start, length)</big></a></dt>
  5523. <dd>
  5524. <p>substr returns a part of the given string. The start
  5525. position is given by the start argument. The first position
  5526. in a string is position 0. And the length argument specifies
  5527. the number of characters to return from the start
  5528. position.</p>
  5529. </dd>
  5530. <dt><a name="sybsql_checkconnect" id=
  5531. "sybsql_checkconnect"><big>
  5532. sybSQL_CheckConnect()</big></a></dt>
  5533. <dd>
  5534. <p>This function returns 1 if the connection to the database
  5535. has been established and 0 otherwise.</p>
  5536. </dd>
  5537. <dt><a name="sybsql_dbuse" id="sybsql_dbuse"><big>
  5538. sybSQL_DBuse(database)</big></a></dt>
  5539. <dd>
  5540. <p>This function issues a Sybase Transact-SQL <b>use</b>
  5541. command for the specified database. The only argument to the
  5542. function is the name of the database to use. Example:
  5543. <code>sybsql_dbuse("pubs2");</code></p>
  5544. <p>The function returns 1 on success and 0 on failure.</p>
  5545. </dd>
  5546. <dt><a name="sybsql_connect" id="sybsql_connect"><big>
  5547. sybSQL_Connect()</big></a></dt>
  5548. <dd>
  5549. <p>This function opens a network connection to the sybase
  5550. server. This function depends on several environment
  5551. variables which must be set by the caller before calling this
  5552. function.</p>
  5553. <p>The environment variables are:</p>
  5554. <p><b>DSQUERY</b> - the alias of the sybase server as defined
  5555. in the sybase interface file.<br />
  5556. <b>DBUSER</b> - connect to the sybase server as this
  5557. user.<br />
  5558. <b>DBPW</b> - password of the user.</p>
  5559. <p>These variables can be set in several ways. If php/fi is
  5560. running as a CGI program, then a shell wrapper can be used to
  5561. set these variables or you can set these variables directly
  5562. in the HTML page using the builtin PHP/FI function
  5563. <b><a href="#putenv">putenv()</a></b>. Instead of using the
  5564. values directly in <b><a href="#putenv">putenv()</a></b>, the
  5565. values can be obtained from form input. The variables can be
  5566. defined in a file and included in the html files with PHP/FI
  5567. <code><a href="#include">include</a></code> statement.</p>
  5568. <p>The function returns 1 on success and 0 on failure.</p>
  5569. </dd>
  5570. <dt><a name="sybsql_exit" id="sybsql_exit"><big>
  5571. sybSQL_Exit()</big></a></dt>
  5572. <dd>
  5573. <p>This function forces a Sybase connection to be shut down.
  5574. If not called, the connection will automatically be closed
  5575. when the PHP page has been fully parsed, so calling this
  5576. function is optional.</p>
  5577. </dd>
  5578. <dt><a name="sybsql_fieldname" id=
  5579. "sybsql_fieldname"><big>sybSQL_Fieldname(index)</big></a></dt>
  5580. <dd>
  5581. <p>This function returns the field name of a regular result
  5582. column. The argument to the function is the field index.
  5583. Example: <code>sybsql_fieldname(0);</code>. NOTE: the field
  5584. index starts at 0.</p>
  5585. <p>If the the result column does not have any name, the
  5586. function returns an empty string ("").</p>
  5587. </dd>
  5588. <dt><a name="sybsql_getfield" id="sybsql_getfield"><big>
  5589. sybSQL_GetField(field)</big></a></dt>
  5590. <dd>
  5591. <p>This function gets the value of a specific column of the
  5592. current result row. The only argument to the function is the
  5593. string specifying the field. Example:
  5594. <code>$value=sybsql_getfield("@10");</code> <b>NOTE</b>:
  5595. <a href="#sybsql_nextrow">sybsql_nextrow()</a> must be called
  5596. before calling this function. sybsql_nextrow() must be called
  5597. if the row pointer needs to be incremented, because this
  5598. function only reads the current row in the row buffer.</p>
  5599. <p>If the specified column has a value, the function returns
  5600. the value as a string otherwise the function returns an empty
  5601. string ("").</p>
  5602. </dd>
  5603. <dt><a name="sybsql_isrow" id="sybsql_isrow"><big>
  5604. sybSQL_IsRow()</big></a></dt>
  5605. <dd>
  5606. <p>This function indicates if the current SQL command
  5607. returned any rows.</p>
  5608. <p>The function returns 1 if the SQL command returned any
  5609. rows and 0 if the command didn't return any rows.</p>
  5610. </dd>
  5611. <dt><a name="sybsql_nextrow" id="sybsql_nextrow"><big>
  5612. sybSQL_NextRow()</big></a></dt>
  5613. <dd>
  5614. <p>This function increments the row pointer to the next
  5615. result row.</p>
  5616. <p>The function returns 1 as long as there are rows left to
  5617. read. If there are no more rows left to read or in case of
  5618. error the function returns 0.</p>
  5619. </dd>
  5620. <dt><a name="sybsql_numfields" id=
  5621. "sybsql_numfields"><big>sybSQL_NumFields()</big></a></dt>
  5622. <dd>
  5623. <p>This function returns the number of fields in a current
  5624. result row.</p>
  5625. <p>The function returns the number of rows in the current
  5626. result row. If there are no fields, the function returns
  5627. 0.</p>
  5628. </dd>
  5629. <dt><a name="sybsql_numrows" id="sybsql_numrows"><big>
  5630. sybSQL_NumRows()</big></a></dt>
  5631. <dd>
  5632. <p>This function returns the number of rows in the current
  5633. result buffer. <b>NOTE:</b> when this function is called, it
  5634. will seek to the first row right away, then it will call
  5635. dbnextrow() until there are no more rows and increment a
  5636. internal counter to calculate the number of rows in the
  5637. result buffer. Then it points back to the very first row.
  5638. Therefore, after calling this function row counter always
  5639. points to the very first row. It's ugly but I don't know any
  5640. other way at this time.</p>
  5641. <p>If there are no rows in the result buffer, the function
  5642. will return 0.</p>
  5643. </dd>
  5644. <dt><a name="sybsql_query" id="sybsql_query"><big>
  5645. sybSQL_Query()</big></a></dt>
  5646. <dd>
  5647. <p>This function submits a Sybase SQL query request to the
  5648. server. The only argument to the function is the query
  5649. string. Example: <code>$rc=sybsql_query("select * from
  5650. authors");</code></p>
  5651. <p>The function returns 1, if the query is passed
  5652. successfully and returns 0 if the request fails.</p>
  5653. </dd>
  5654. <dt><a name="sybsql_result" id="sybsql_result"><big>
  5655. sybSQL_Result(string)</big></a></dt>
  5656. <dd>
  5657. <p>This function prints specific fields of the current result
  5658. row. The only argument to the function is a string which
  5659. holds information about the fields to be printed. A field is
  5660. specified with a @ followed by a number. For example, @0
  5661. means first row, @10 means 11th row. Note that the field
  5662. number starts at 0. The function is perhaps best illustrated
  5663. with a complete example:</p>
  5664. <pre>
  5665. &lt;?
  5666. /*
  5667. ** assuming all the necessary variables for
  5668. ** connection is already set. please note, NO error checking is
  5669. ** done. You should always check return code of a function.
  5670. */
  5671. /* connect */
  5672. $rc=sybsql_connect();
  5673. /* use the pub2 database */
  5674. $rc=sybsql_dbuse("pubs2");
  5675. /* send the SQL request */
  5676. $rc=sybsql_query("select * from authors");
  5677. $i=0;
  5678. /* find the no of rows returned */
  5679. $nrows=sybsql_numrows();
  5680. /* start table */
  5681. echo "&lt;table border&gt;\n";
  5682. /*
  5683. ** print only first and 2nd field
  5684. */
  5685. while($i&lt;$nrows) {
  5686. sybsql_result("&lt;tr&gt;&lt;td&gt;@0&lt;/td&gt;@1&lt;/td&gt;&lt;/tr&gt;\n");
  5687. $i++;
  5688. }
  5689. /* end table */
  5690. echo "&lt;/table&gt;\n";
  5691. &gt;
  5692. </pre>
  5693. <p>The above example uses HTML table to format the output. Of
  5694. course, any other valid HTML tags can be used.</p>
  5695. </dd>
  5696. <dt><a name="sybsql_result_all" id=
  5697. "sybsql_result_all"><big>
  5698. sybSQL_Result_All()</big></a></dt>
  5699. <dd>
  5700. <p>This function prints all rows in the current result
  5701. buffer. The result is printed in a hard coded HTML table
  5702. format. Note that this function should not be called inside a
  5703. loop. The function will print the name of the columns if
  5704. there are any column headings in the output.</p>
  5705. </dd>
  5706. <dt><a name="sybsql_seek" id="sybsql_seek"><big>
  5707. sybSQL_Seek(row)</big></a></dt>
  5708. <dd>
  5709. <p>This function sets the requested row number as the current
  5710. row in the row buffer. The only argument to the function is
  5711. the row number. Example: <code>$rc=sybsql_seek(10);</code>
  5712. Note, row number starts at 0.</p>
  5713. <p>The function returns 1 if the seek succeeds and 0 if the
  5714. seek fails. When all of the rows in the current result buffer
  5715. have been visited, the row pointer points to the last row. If
  5716. it is needed to go backward and visit some more rows, this
  5717. function can be used for this purpose.</p>
  5718. </dd>
  5719. <dt><a name="symlink" id="symlink"><big>
  5720. Symlink(target,link)</big></a></dt>
  5721. <dd>
  5722. <p>Symlink() creates a symbolic link. See the <a href=
  5723. "#link">Link()</a> function to create hard links.</p>
  5724. </dd>
  5725. <dt><a name="syslog" id="syslog"><big>
  5726. Syslog(level,message)</big></a></dt>
  5727. <dd>
  5728. <p>Syslog() logs messages to the system using UNIX's
  5729. syslog(3) feature. See your UNIX man page for more details.
  5730. See also <a href="#initsyslog">InitSyslog()</a>, <a href=
  5731. "#openlog">OpenLog()</a> and <a href=
  5732. "#closelog">CloseLog()</a>.</p>
  5733. </dd>
  5734. <dt><a name="system" id="system"><big>
  5735. System(command_string [,return_var])</big></a></dt>
  5736. <dd>
  5737. <p>System is just like the C <em>system()</em> command in
  5738. that it executes the given unix command and outputs the
  5739. result. If a variable is provided as the second argument,
  5740. then the return status code of the executed unix command will
  5741. be written to this variable. Note, that if you are going to
  5742. allow data coming from user input to be passed to this System
  5743. function, then you should be using the <a href=
  5744. "#escapeshellcmd">EscapeShellCmd()</a> function to make sure
  5745. that users cannot trick the system into executing arbitrary
  5746. commands. The System() call also automatically flushes the
  5747. Apache output buffer after each line of output if PHP is
  5748. running as an Apache module. If you need to execute a command
  5749. and have all the data from the command passed directly back
  5750. without any interference, use the <a href=
  5751. "#passthru">PassThru()</a> function. See also the <a href=
  5752. "#exec">Exec</a> function.</p>
  5753. </dd>
  5754. <dt><a name="tan" id="tan"><big>
  5755. Tan(arg)</big></a></dt>
  5756. <dd>
  5757. <p>Sin returns the tangent of arg in radians. See also
  5758. <a href="#sin">Sin()</a> and <a href="#cos">Cos()</a></p>
  5759. </dd>
  5760. <dt><a name="tempnam" id="tempnam"><big>
  5761. TempNam(path, prefix)</big></a></dt>
  5762. <dd>
  5763. <p>TempNam returns a unique filename located in the directory
  5764. indicated by path with filename prefix given by prefix. It is
  5765. identical to the Unix C tempnam() function.</p>
  5766. </dd>
  5767. <dt><a name="time" id="time"><big>
  5768. Time()</big></a></dt>
  5769. <dd>
  5770. <p>Time simply returns the current local time in seconds
  5771. since Unix epoch (00:00:00 Jan. 1 1970). It is equivalent to
  5772. calling <a href="#date">Date("U")</a>. If you need better
  5773. than per-second granularity, use the <a href=
  5774. "#microtime">Microtime</a> function.</p>
  5775. </dd>
  5776. <dt><a name="umask" id="umask"><big>
  5777. Umask([mask])</big></a></dt>
  5778. <dd>
  5779. <p>Umask(<i>mask</i>) sets PHP's umask to <i>mask</i> &amp;
  5780. 0777 and returns the old umask. If PHP/FI is an Apache
  5781. module, Apache's old umask is restored when PHP/FI has
  5782. finished. <i>mask</i> must be specified in <a href=
  5783. "#octal">octal</a> notation, like for <a href=
  5784. "#chmod">ChMod()</a>. Umask() without arguments simply
  5785. returns the current umask.</p>
  5786. </dd>
  5787. <dt><a name="uniqid" id="uniqid"><big>
  5788. UniqId()</big></a></dt>
  5789. <dd>
  5790. <p>UniqId returns a prefixed unique identifier based on
  5791. current time in microseconds. The prefix can be useful for
  5792. instance if you generate identifiers simultaneously on
  5793. several hosts that might happen to generate the identifier at
  5794. the same microsecond. The prefix can be up to 114 characters
  5795. long.</p>
  5796. </dd>
  5797. <dt><a name="unlink" id="unlink"><big>
  5798. Unlink(filename)</big></a></dt>
  5799. <dd>
  5800. <p>Unlink deletes the given filename. Similar to the Unix C
  5801. unlink() function. See the <a href="#rmdir">RmDir()</a>
  5802. function for removing directories.</p>
  5803. </dd>
  5804. <dt><a name="unset" id="unset"><big>
  5805. UnSet($var)</big></a></dt>
  5806. <dd>
  5807. <p>UnSet undefines the given variable. In the case of an
  5808. array, the entire array is cleared. Individual array elements
  5809. may also be unset.</p>
  5810. </dd>
  5811. <dt><a name="urldecode" id="urldecode"><big>
  5812. UrlDecode(arg)</big></a></dt>
  5813. <dd>
  5814. <p>UrlDecode decodes a string encoded with the <a href=
  5815. "#urlencode">UrlEncode</a> function. In typical use, it is
  5816. not necessary to decode URL Encoded strings because these are
  5817. automatically decoded when strings are passed between pages.
  5818. However, for completeness sake, this function has been
  5819. included.</p>
  5820. </dd>
  5821. <dt><a name="urlencode" id="urlencode"><big>
  5822. UrlEncode(arg)</big></a></dt>
  5823. <dd>
  5824. <p>UrlEncode encodes any characters from arg which are not
  5825. one of "a-zA-Z0-9_-." by replacing them with %xx where xx is
  5826. their ASCII value in hexadecimal. The encoded string is
  5827. returned.</p>
  5828. </dd>
  5829. <dt><a name="usleep" id="usleep"><big>
  5830. USleep(microsecs)</big></a></dt>
  5831. <dd>
  5832. <p>Sleep will delay for the given number of microseconds.
  5833. Similar to the Unix C usleep() function. See also the
  5834. <a href="#sleep">Sleep()</a> function.</p>
  5835. </dd>
  5836. <dt><a name="virtual" id="virtual"><big>
  5837. Virtual(filename)</big></a></dt>
  5838. <dd>
  5839. <p>Virtual is an Apache-specific function which is equivalent
  5840. to &lt;!--#include virtual...--&gt; in mod_include. It
  5841. performs an Apache sub-request. It is useful for including
  5842. CGI scripts or .shtml files, or anything else that you would
  5843. parse through Apache (for .phtml files, you'd probably want
  5844. to use &lt;?Include&gt;.</p>
  5845. </dd>
  5846. </dl>
  5847. <hr />
  5848. <h2><a name="addfunc" id="addfunc">Adding your own internal
  5849. functions to PHP/FI</a></h2>It may well be that the set of
  5850. functions provided by PHP/FI does not include a particular
  5851. function that you may need. By carefully following the steps
  5852. described below, it is possible for you to add your own functions
  5853. to PHP/FI.
  5854. <p>Before you start hacking away at the internals of PHP/FI you
  5855. need to grab a copy of the latest version of Bison. Bison is
  5856. GNU's implementation of YACC (Yet Another Compiler Compiler). The
  5857. YACC that came with your operating system may or may not be good
  5858. enough, but just to make sure, go grab Bison. You can find it at
  5859. <a href=
  5860. "ftp://prep.ai.mit.edu/pub/gnu">ftp://prep.ai.mit.edu/pub/gnu</a>.</p>
  5861. <p>You should also have a look at the Makefile and turn on
  5862. debugging. Simply uncomment the <strong>DEBUG</strong> line in
  5863. the Makefile. The output file of debug information is specified
  5864. by <strong>DEBUG_FILE</strong> in <em>php.h</em>. It is by
  5865. default set to <em>/tmp/php.err</em>. You can change this to suit
  5866. your needs.</p>
  5867. <p>A final thing you might want to keep in mind is that php runs
  5868. as the same user id as httpd on your system, unless of course you
  5869. are running it with the setuid bit set, and this httpd user does
  5870. not generally have write access to the various directories. This
  5871. means that if you do something that causes php to core dump, you
  5872. will not get a core file. The easy way around this is to make the
  5873. directory where you keep your test .html files writable to all.
  5874. PHP changes its current directory to the directory of the .html
  5875. file it is reading and will thus dump its core there if it
  5876. can.</p>
  5877. <p>In the following steps we will use the <em>Time()</em>
  5878. function to illustrate how to add a function.</p>
  5879. <dl>
  5880. <dt><strong>Step 1 - Defining the grammar of your
  5881. Function</strong></dt>
  5882. <dd>
  5883. <p>If your function takes 0 to 6 arguments, there are
  5884. predefined grammars available. You can skip this step.</p>
  5885. <p>The grammar of your function is defined in the
  5886. <em>parse.raw</em> file. The first thing to add is a token. A
  5887. token is an upper case keyword which is usually the same as
  5888. your function name. All the tokens are defined near the top
  5889. of the parse.raw file. The order doesn't matter. Then you
  5890. need to build your actual YACC grammar rule. Look at the
  5891. existing rules and find a function that is similar to the one
  5892. you are adding. Keep in mind that most normal functions are
  5893. standard functions that read their arguments from the
  5894. expression stack. Your function will most likely fall into
  5895. this group in which case you won't need to touch the
  5896. <em>parse.raw</em> file.</p>
  5897. </dd>
  5898. <dt><strong>Step 2 - Adding your function to the lexical
  5899. analyzer hash table</strong></dt>
  5900. <dd>
  5901. <p>To do this, edit <em>lex.c</em> and find the hash table
  5902. near the top of the file. Look for the line, <tt>static
  5903. cmd_table_t cmd_table[22][30] = {</tt>, which defines the
  5904. beginning of the hash table. The <tt>[22][30]</tt> defines
  5905. the size of the 2 dimensional array which holds the hash
  5906. table. The 22 is one greater than the maximum function name
  5907. length and the 30 refers to the maximum number of functions
  5908. in any one hash list. If you exceed either of these limits,
  5909. simply increase them right here.</p>
  5910. <p>This hash table would probably rate as the absolute
  5911. simplest hash table in the entire world. The hash value is
  5912. the length of the string of the function name to be hashed.
  5913. So, for our <em>Time()</em> example, we need to add an entry
  5914. for hash value 4. Therefore we add the following line to the
  5915. hash list for 4:</p>
  5916. <pre>
  5917. { "time",INTFUNC0,UnixTime },
  5918. </pre>
  5919. <p>This entry maps a string to the INTFUNC0 token. You can
  5920. look up the grammar for the INTFUNC0 token in
  5921. <em>parse.raw</em> and you will see that it is a generic
  5922. grammar for an internal function call with 0 arguments. The
  5923. string, in quotes above, is the actual string that you will
  5924. be using in the .html files to call your function. Keep in
  5925. mind that PHP/FI function names are <strong>not</strong> case
  5926. sensitive. And the final <b>UnixTime</b> element is the
  5927. actual function to be called.</p>
  5928. </dd>
  5929. <dt><strong>Step 3 - Write your actual Function</strong></dt>
  5930. <dd>
  5931. <p>You can actually write your function in any language you
  5932. like, as long as it is callable through the normal C function
  5933. call convention and you have a way of creating either an
  5934. object file or a library file compatible with the linker on
  5935. your system. In general, we will assume that you are writing
  5936. your function in C. All the functions that come with PHP/FI
  5937. have been written in C. The Time() function, or UnixTime() as
  5938. it is called internally in PHP can be found in
  5939. <em>date.c</em> and looks like this:</p>
  5940. <pre>
  5941. void UnixTime(void) {
  5942. char temp[32];
  5943. sprintf(temp,"%ld",(long)time(NULL));
  5944. Push(temp,LNUMBER);
  5945. }
  5946. </pre>
  5947. <p>Note that the function is void. This indicates that it
  5948. doesn't return anything. This may seem confusing to you
  5949. because obviously the function needs to somehow return the
  5950. time. The time is returned, but not as the return value of
  5951. the function. It is pushed onto what is called an expression
  5952. stack. The expression stack is simply a stack of strings and
  5953. an associated type. PHP/FI understands only 3 basic variable
  5954. types: STRING, LNUMBER and DNUMBER. STRING is a character
  5955. string, LNUMBER is a long integer and DNUMBER is a double, or
  5956. floating point, value. In this Time() example, the value to
  5957. be returned is the time expressed in Unix format (number of
  5958. seconds since Jan.1 1970) and is thus an integer. The
  5959. expression stack only accepts strings, so we sprintf the long
  5960. integer into a string and push it onto the stack indicating
  5961. that it is actually a long integer with the line:
  5962. <tt>Push(temp,LNUMBER);</tt></p>
  5963. </dd>
  5964. <dt><strong>Step 4 - Add your function prototype to
  5965. php.h</strong></dt>
  5966. <dd>
  5967. <p>In the bottom half of the <em>php.h</em> file you will
  5968. find a complete list of prototypes of all the functions in
  5969. php. They are grouped by the files in which they appear.
  5970. Simply add your prototype to an appropriate place in this
  5971. file. For our Time() example the following line is added:</p>
  5972. <pre>
  5973. void UnixTime(void);
  5974. </pre>
  5975. </dd>
  5976. <dt><strong>Step 5 - Compile</strong></dt>
  5977. <dd>
  5978. <p>You have to remember to re-make the parser whenever you
  5979. make a change to the <em>parse.raw</em> file. Type:
  5980. <strong>make parser</strong> to do this. You must have at
  5981. least version 1.25 of Bison in order to make the PHP parser.
  5982. Then do a normal compile by typing: <strong>make</strong>
  5983. once that is done.</p>
  5984. </dd>
  5985. <dt><strong>Step 6 - Send me your additions!</strong></dt>
  5986. <dd>
  5987. <p>If you would like your functions added to the next release
  5988. of PHP/FI, send them to me. The best way is probably to make
  5989. a context-sensitive diff. To do that, you need a copy of a
  5990. clean unmodified distribution. Simply do a, <strong>diff
  5991. -c</strong> on the files you have changed comparing them to
  5992. the original files. Please don't send me a diff of the
  5993. changes in <em>parse.c</em> since that file is automatically
  5994. generated. Send me the diff from <em>parse.raw</em>
  5995. instead.</p>
  5996. </dd>
  5997. </dl>
  5998. <p>The Time() example illustrated the steps involved in adding a
  5999. function. Chances are that the function you wish to add is quite
  6000. a bit more complex than this example. You will probably want to
  6001. be able to pass arguments to your function and have it manipulate
  6002. these arguments in some manner. You may even want to have it
  6003. callable in different ways. These concepts will be illustrated by
  6004. the PHP/FI crypt() function. See also the section entitled
  6005. <a href="#hacknotes">Notes for Code Hacks</a> for some more
  6006. technical details about writing code for PHP/FI.</p>
  6007. <p>The Crypt() Grammar in <em>parse.raw</em>:</p>
  6008. <pre>
  6009. %token CRYPT
  6010. .
  6011. .
  6012. .
  6013. | CRYPT '(' expr ',' expr ')'
  6014. {
  6015. if(GetCurrentState(NULL) || inCase || inElseIf) Crypt(1);
  6016. }
  6017. | CRYPT '(' expr ')'
  6018. {
  6019. if(GetCurrentState(NULL) || inCase || inElseIf) Crypt(0);
  6020. }
  6021. </pre>
  6022. <p>Here it is shown how to define a grammar which lets you call a
  6023. function with either 1 or 2 arguments. You could write different
  6024. functions to handle the two cases, or simply send a mode
  6025. parameter as is done here to indicate the mode in which the
  6026. function is called. Note that in this case you cannot use one of
  6027. the pre-defined INTFUNCn grammars since your function can take a
  6028. variable number of arguments.</p>
  6029. <p>The other aspect that is shown is how to actually represent
  6030. function arguments. In most cases you will want to use the
  6031. <strong>expr</strong> identifier. This identifier means that the
  6032. argument is an expression. An expression can be a literal value,
  6033. a function call or a combination of many expressions. See
  6034. parse.raw for the complete yacc grammar definition for
  6035. expressions for more details.</p>
  6036. <p>The Hash Table entry in <em>lex.c</em>:</p>
  6037. <pre>
  6038. { "crypt",CRYPT,NULL },
  6039. </pre>
  6040. <p>Notice that the last item is a NULL in this case since the
  6041. function call is handled in <em>parse.raw</em> directly. If you
  6042. used an INTFUNCn grammar, then you would put the name of your
  6043. function in place of this NULL. The actual Crypt() function in
  6044. <em>crypt.c</em>:</p>
  6045. <pre>
  6046. /*
  6047. * If mode is non-zero, a salt is expected.
  6048. * If mode is zero, a pseudo-random salt will be selected.
  6049. */
  6050. void Crypt(int mode) {
  6051. #if HAVE_CRYPT
  6052. Stack *s;
  6053. char salt[8];
  6054. char *enc;
  6055. salt[0] = '\0';
  6056. if(mode) {
  6057. s = Pop();
  6058. if(!s) {
  6059. Error("Stack error in crypt");
  6060. return;
  6061. }
  6062. if(s-&gt;strval) strncpy(salt,s-&gt;strval,2);
  6063. }
  6064. s = Pop();
  6065. if(!s) {
  6066. Error("Stack error in crypt");
  6067. return;
  6068. }
  6069. if(!salt[0]) {
  6070. salt[0] = 'A' + (time(NULL) % 26);
  6071. salt[1] = 'a' + (time(NULL) % 26);
  6072. salt[2] = '\0';
  6073. }
  6074. enc = (char *)crypt(s-&gt;strval,salt);
  6075. #if DEBUG
  6076. Debug("Crypt returned [%s]\n",enc);
  6077. #endif
  6078. Push(enc,STRING);
  6079. #else
  6080. Error("No crypt support compiled into this version");
  6081. #endif
  6082. }
  6083. </pre>
  6084. <p>The most important aspect of this function is the <strong>s =
  6085. Pop()</strong> call. The arguments to the function must be popped
  6086. off the expression stack one by one. When you write a function
  6087. which takes multiple arguments, remember that a stack is a
  6088. LAST-IN, FIRST-OUT data structure. This means that you will be
  6089. popping your arguments off the stack in reverse order. The last
  6090. argument is popped off first. In the above example we check to
  6091. see if we are in the 2 argument mode. If we are, we pop the
  6092. argument off the stack and save it. Then we pop the next argument
  6093. off the stack. Pop() returns a pointer to a Stack structure (s).
  6094. The Stack structure looks like this (from <em>php.h</em>):</p>
  6095. <pre>
  6096. /* Expression Stack */
  6097. typedef struct Stack {
  6098. short type;
  6099. unsigned char *strval;
  6100. long intval;
  6101. double douval;
  6102. VarTree *var;
  6103. struct Stack *next;
  6104. } Stack;
  6105. </pre>
  6106. <p>The <em>type</em> will generally be one of STRING, LNUMBER or
  6107. DNUMBER. The <em>strval</em>, <em>intval</em>, and
  6108. <em>douval</em> components are the string, integer and double
  6109. representations of the value respectively. If the expression is
  6110. actually a defined variable, the <em>var</em> component contains
  6111. a pointer to the variable structure which defines this
  6112. variable.</p>
  6113. <p>In our Crypt() function we are only interested in the string
  6114. value of the argument, so we use <em>s-&gt;strval</em>. Many
  6115. PHP/FI functions can do different things depending on the type of
  6116. the variable simply by checking <em>s-&gt;type</em> and using
  6117. <em>s-&gt;strval</em>, <em>s-&gt;intval</em> and/or
  6118. <em>s-&gt;douval</em> appropriately.</p>
  6119. <p>After calling the <strong>real</strong> crypt() function and
  6120. getting the encrypted string, our Crypt() function calls
  6121. <em>Push(enc,STRING);</em> to push the return value onto the
  6122. expression stack. It should be noted that the expression stack is
  6123. cleared after each PHP/FI line, so if you push expressions onto
  6124. this stack that are never popped by anything, it won't
  6125. matter.</p>
  6126. <p>The <em>Debug()</em> call in the Crypt() example shows how to
  6127. add debugging output to your function. Debug() is a varags
  6128. (variable argument list) function just like printf.</p>
  6129. <hr />
  6130. <h2><a name="hacknotes" id="hacknotes">Notes for
  6131. Code-Hacks</a></h2>
  6132. <p>Memory management within PHP/FI is a tricky thing. Since we
  6133. can run as a server module, we have to be very careful about
  6134. memory resources. Not only do we need to be reentrant, but we
  6135. also need to be handle the fact that we can receive a timeout
  6136. signal at any time at which point we drop out of the module. We
  6137. get no warning, and we get no time to free any memory that we may
  6138. have allocated. And this memory has to be freed, or the data
  6139. space of the httpd process we are linked to could grow
  6140. indefinitely. This also applies when PHP is running in CGI mode
  6141. since it can be set up to run as a FastCGI persistent
  6142. process.</p>
  6143. <p>The solution is to use sub-pools of memory. These pools are
  6144. automatically cleared by Apache when a session is terminated, or
  6145. in the case of a FastCGI persistent process, these pools are
  6146. cleared in <em>main.c</em> every time the FastCGI wrapper loop
  6147. executes. Three such pools are used at the moment. They are
  6148. numbered 0,1 and 2. The sub-pool number is the first argument to
  6149. the <em>emalloc</em> and <em>estrdup</em> functions.</p>
  6150. <dl>
  6151. <dt><strong>Pool 0 - Session lifespan</strong></dt>
  6152. <dd>Any memory allocated from this pool will span the entire
  6153. session. It is a good idea to keep the use of this pool as low
  6154. as possible. For example, if someone makes a while loop that
  6155. iterates 1000 times and within this while loop they call
  6156. something which allocates memory from pool 0, then this memory
  6157. will be allocated 1000 times. This is a quick way to use up all
  6158. alloted data space.</dd>
  6159. <dt><strong>Pool 1 - Temporary storage (shortest
  6160. lifespan)</strong></dt>
  6161. <dd>If a temporary work buffer is needed for something within a
  6162. function, the memory for it must come from this pool. This pool
  6163. is cleared on every call to yylex(). ie. the memory is lost
  6164. just about as soon as you leave a function.</dd>
  6165. <dt><strong>Pool 2 - Expression space (medium
  6166. lifespan)</strong></dt>
  6167. <dd>This pool exists for the duration of an expression. An
  6168. expression in this context being a full PHP/FI command line. It
  6169. will not get cleared within functions since the higher level
  6170. expression which called the function has not been completed
  6171. until the function returns. The ClearIt flag in the yylex()
  6172. function indicates when it is safe to clear this pool.</dd>
  6173. </dl>
  6174. <p>The use of sub-pools completely eliminates the need to
  6175. explicitly free memory anywhere in the code, with the one
  6176. exception being memory allocated using a regular malloc call by
  6177. various libraries that could be linked into PHP. The gdbm library
  6178. is one such example.</p>
  6179. <?php site_footer(); ?>