downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.php-sapi-name.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.info.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.php-sapi-name.php',
   
1 => 'php_sapi_name',
  ),
 
'up' =>
  array (
   
0 => 'ref.info.php',
   
1 => 'PHP Options/Info Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.php-logo-guid.php',
   
1 => 'php_logo_guid',
  ),
 
'next' =>
  array (
   
0 => 'function.php-uname.php',
   
1 => 'php_uname',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.php-sapi-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">php_sapi_name</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">php_sapi_name</span> &mdash; <span class="dc-title">Returns the type of interface between web server and PHP</span></p>

 </div>
 
 <a name="function.php-sapi-name.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>php_sapi_name</b></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="simpara">
   Returns a lowercase string that describes the type of interface
   (the Server API, SAPI) that PHP is using. For example, in CLI PHP this
   string will be &quot;cli&quot; whereas with Apache it may have several different
   values depending on the exact SAPI used. Possible values are listed
   below.
  </p>
 </div>


 <a name="function.php-sapi-name.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the interface type, as a lowercase string.
  </p>
  <p class="para">
   Although not exhaustive, the possible return values include
   <i>aolserver</i>, <i>apache</i>,
   <i>apache2filter</i>, <i>apache2handler</i>,
   <i>caudium</i>, <i>cgi</i> (until PHP 5.3),
   <i>cgi-fcgi</i>, <i>cli</i>,
   <i>continuity</i>, <i>embed</i>,
   <i>isapi</i>, <i>litespeed</i>,
   <i>milter</i>, <i>nsapi</i>,
   <i>phttpd</i>, <i>pi3web</i>, <i>roxen</i>,
   <i>thttpd</i>, <i>tux</i>, and <i>webjames</i>.
  </p>
 </div>


 <a name="function.php-sapi-name.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>php_sapi_name()</b> example</b></p>
    <div class="example-contents para"><p>
     This example checks for the substring <i>cgi</i>
     because it may also be <i>cgi-fcgi</i>.
    </p></div>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sapi_type&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">php_sapi_name</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$sapi_type</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #DD0000">'cgi'</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"You&nbsp;are&nbsp;using&nbsp;CGI&nbsp;PHP\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"You&nbsp;are&nbsp;not&nbsp;using&nbsp;CGI&nbsp;PHP\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.php-sapi-name.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>:
   <b>An alternative approach</b><br />
  
    The PHP constant <b><tt class="constant">PHP_SAPI</tt></b> has the same value
    as <b>php_sapi_name()</b>.
   <br />
  </p></blockquote>
  <div class="tip"><b class="tip">Tip</b>
   <h1 class="title">A potential gotcha</h1>
   <p class="para">
    The defined <acronym title="Server Application Programming Interface">SAPI</acronym> may not be obvious, because for
    example instead of <i>apache</i> it may be defined as
    <i>apache2handler</i> or <i>apache2filter</i>.
   </p>
  </div>
 </div>


 <a name="function.php-sapi-name.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="reserved.constants.php#reserved.constants.core" class="link">PHP_SAPI</a></li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites