<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.phar.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'phar.webphar.php',
    1 => 'Phar::webPhar',
    2 => 'Routes a request from a web browser to an internal file within the phar archive',
  ),
  'up' => 
  array (
    0 => 'class.phar.php',
    1 => 'Phar',
  ),
  'prev' => 
  array (
    0 => 'phar.unlinkarchive.php',
    1 => 'Phar::unlinkArchive',
  ),
  'next' => 
  array (
    0 => 'class.phardata.php',
    1 => 'PharData',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/Phar/webPhar.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phar.webphar" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::webPhar</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Phar::webPhar</span> &mdash; <span class="dc-title">Routes a request from a web browser to an internal file within the phar archive</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phar.webphar-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Phar::webPhar</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$alias</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$index</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$fileNotFoundScript</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$mimeTypes</code><span class="initializer"> = []</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span></span> <code class="parameter">$rewrite</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Phar::webPhar()</strong></span> serves as <span class="function"><a href="phar.mapphar.php" class="function">Phar::mapPhar()</a></span> for 
   web-based phars.  This method parses <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['REQUEST_URI']</a></var> and 
   routes a request from a web browser to an internal file within the phar archive.  
   It simulates a web server, routing requests to the correct file, echoing the correct 
   headers and parsing PHP files as needed.  Combined with <span class="function"><a href="phar.mungserver.php" class="function">Phar::mungServer()</a></span> 
   and <span class="function"><a href="phar.interceptfilefuncs.php" class="function">Phar::interceptFileFuncs()</a></span>, any web application can be used 
   unmodified from a phar archive.
  </p>
  <p class="para">
   <span class="function"><strong>Phar::webPhar()</strong></span> should only be
   called from the stub of a phar archive (see <a href="phar.fileformat.stub.php" class="link">here</a>
   for more information on what a stub is).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phar.webphar-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">alias</code></dt>
     <dd>
      <p class="para">
       The alias that can be used in <code class="literal">phar://</code> URLs to
       refer to this archive, rather than its full path.
      </p>
     </dd>
    
    
     <dt><code class="parameter">index</code></dt>
     <dd>
      <p class="para">
       The location within the phar of the directory index.
      </p>
     </dd>
    
    
     <dt><code class="parameter">fileNotFoundScript</code></dt>
     <dd>
      <p class="para">
       The location of the script to run when a file is not found.  This
       script should output the proper HTTP 404 headers.
      </p>
     </dd>
    
    
     <dt><code class="parameter">mimeTypes</code></dt>
     <dd>
      <p class="para">
       An array mapping additional file extensions to MIME type.
       If the default mapping is sufficient, pass an empty array.
       By default, these extensions are mapped to these MIME types:
       <div class="example-contents">
        <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$mimes </span><span style="color: #007700">= array(<br />    </span><span style="color: #DD0000">'phps' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">PHPS</span><span style="color: #007700">, </span><span style="color: #FF8000">// pass to highlight_file()<br />    </span><span style="color: #DD0000">'c' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'cc' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'cpp' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'c++' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'dtd' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'h' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'log' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'rng' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'txt' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'xsd' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'php' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">PHP</span><span style="color: #007700">, </span><span style="color: #FF8000">// parse as PHP<br />    </span><span style="color: #DD0000">'inc' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">PHP</span><span style="color: #007700">, </span><span style="color: #FF8000">// parse as PHP<br />    </span><span style="color: #DD0000">'avi' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'video/avi'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'bmp' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/bmp'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'css' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/css'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'gif' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/gif'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'htm' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/html'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'html' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/html'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'htmls' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/html'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'ico' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/x-ico'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'jpe' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/jpeg'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'jpg' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/jpeg'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'jpeg' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/jpeg'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'js' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'application/x-javascript'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'midi' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'audio/midi'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mid' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'audio/midi'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mod' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'audio/mod'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mov' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'movie/quicktime'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mp3' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'audio/mp3'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mpg' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'video/mpeg'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'mpeg' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'video/mpeg'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'pdf' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'application/pdf'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'png' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/png'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'swf' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'application/shockwave-flash'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'tif' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/tiff'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'tiff' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/tiff'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'wav' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'audio/wav'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'xbm' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'image/xbm'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'xml' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/xml'</span><span style="color: #007700">,<br />);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
       </div>

      </p>
     </dd>
    
    
     <dt><code class="parameter">rewrite</code></dt>
     <dd>
      <p class="para">
       The rewrites function is passed a string as its only parameter and must return a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </p>
      <p class="para">
       If you are using fast-cgi or cgi then the parameter passed to the function is the value of the 
       <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['PATH_INFO']</a></var> variable. Otherwise, the parameter passed to the function is the value
       of the <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['REQUEST_URI']</a></var> variable.
      </p>
      <p class="para">
       If a string is returned it is used as the internal file path. If <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned then webPhar() will
       send a HTTP 403 Denied Code.
      </p>
     </dd>
    
   </dl>
  </p>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.webphar-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No value is returned.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.webphar-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> when unable to open the internal
   file to output, or if
   called from a non-stub.  If an invalid array value is passed into
   <code class="parameter">mimeTypes</code> or an invalid callback is passed into <code class="parameter">rewrite</code>, then
   <span class="classname"><a href="class.unexpectedvalueexception.php" class="classname">UnexpectedValueException</a></span> is thrown.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-phar.webphar-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">fileNotFoundScript</code> and <code class="parameter">rewrite</code> are nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-phar.webphar-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>Phar::webPhar()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     With the example below, the created phar will display <code class="literal">Hello World</code>
     if one browses to <code class="literal">/myphar.phar/index.php</code> or to
     <code class="literal">/myphar.phar</code>, and will display the source of
     <code class="literal">index.phps</code> if one browses to <code class="literal">/myphar.phar/index.phps</code>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// creating the phar archive:<br /></span><span style="color: #007700">try {<br />    </span><span style="color: #0000BB">$phar </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">$phar</span><span style="color: #007700">[</span><span style="color: #DD0000">'index.php'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'&lt;?php echo "Hello World"; ?&gt;'</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$phar</span><span style="color: #007700">[</span><span style="color: #DD0000">'index.phps'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'&lt;?php echo "Hello World"; ?&gt;'</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStub</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;?php<br />Phar::webPhar();<br />__HALT_COMPILER(); ?&gt;'</span><span style="color: #007700">);<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// handle error here<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-phar.webphar-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="phar.mungserver.php" class="function" rel="rdfs-seeAlso">Phar::mungServer()</a> - Defines a list of up to 4 $_SERVER variables that should be modified for execution</span></li>
    <li><span class="function"><a href="phar.interceptfilefuncs.php" class="function" rel="rdfs-seeAlso">Phar::interceptFileFuncs()</a> - Instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>