<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: PHP Server API Differences</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/</link>
	<description></description>
	<pubDate>Thu, 21 Aug 2008 22:50:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: SitePoint Blogs &#187; eZ components – new competition for Zend PHP Framework</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-11220</link>
		<dc:creator>SitePoint Blogs &#187; eZ components – new competition for Zend PHP Framework</dc:creator>
		<pubDate>Sun, 27 Nov 2005 17:07:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-11220</guid>
		<description>[...] Beyond that, Zend’s framework offers a search and a URI component. While I’m still wondering how the former could look like, I’m already hoping for the latter one to be “the one class to rule them all” as answer to our URI problems. eZ, on the other hand, offers a broader set of tools: On one hand we’ve got generic components like Cache, Configuration, Template and Translation, on the other hand there are more concrete tools like Archive, File, Image*, Mail and PhpGenerator. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Beyond that, Zend’s framework offers a search and a URI component. While I’m still wondering how the former could look like, I’m already hoping for the latter one to be “the one class to rule them all” as answer to our URI problems. eZ, on the other hand, offers a broader set of tools: On one hand we’ve got generic components like Cache, Configuration, Template and Translation, on the other hand there are more concrete tools like Archive, File, Image*, Mail and PhpGenerator. [&#8230;]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Demian Turner</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10720</link>
		<dc:creator>Demian Turner</dc:creator>
		<pubDate>Sat, 12 Nov 2005 00:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10720</guid>
		<description>this method, albeit procedural, assigns a correct value to $_SERVER['PHP_SELF'] regardless of apache 1/2, cgi/module or IIS. You will need to remove logic for the frontScriptName $conf element.

&lt;code&gt;
    /**
     * Resolves PHP_SELF var depending on implementation, ie apache, iis, cgi, etc.
     *
     * @abstract
     */
    function resolveServerVars($conf = null)
    {
        //  it's apache
        if (!empty($_SERVER['PHP_SELF']) &#38;&#38; !empty($_SERVER['REQUEST_URI'])) {

            //  however we're running from cgi, so populate PHP_SELF info from REQUEST_URI
            if (strpos(php_sapi_name(), 'cgi') !== false) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];

            //  a ? is part of $conf['site']['frontScriptName'] and REQUEST_URI has more info
            } elseif ((strlen($_SERVER['REQUEST_URI']) &#62; strlen($_SERVER['PHP_SELF'])
                    &#38;&#38; strstr($_SERVER['REQUEST_URI'], '?')
                    &#38;&#38; !isset($conf['setup']))) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];

            // we don't want to have index.php in our url, so REQUEST_URI as more info
            } elseif ($conf['site']['frontScriptName'] == false) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];
            } else {
                //  do nothing, PHP_SELF is valid
            }

        //  it's IIS
        } else {
            $frontScriptName = is_null($conf) ? 'index.php' : $conf['site']['frontScriptName'];
            if (substr($_SERVER['SCRIPT_NAME'], -1, 1) != substr($frontScriptName, -1, 1)) {
                $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] . '?' . @$_SERVER['QUERY_STRING'];
            } else {
                $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] . @$_SERVER['QUERY_STRING'];
            }

        }
    }
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>this method, albeit procedural, assigns a correct value to $_SERVER[&#8217;PHP_SELF&#8217;] regardless of apache 1/2, cgi/module or IIS. You will need to remove logic for the frontScriptName $conf element.</p>
<code>
    /**
     * Resolves PHP_SELF var depending on implementation, ie apache, iis, cgi, etc.
     *
     * @abstract
     */
    function resolveServerVars($conf = null)
    {
        //  it's apache
        if (!empty($_SERVER['PHP_SELF']) &amp;&amp; !empty($_SERVER['REQUEST_URI'])) {

            //  however we're running from cgi, so populate PHP_SELF info from REQUEST_URI
            if (strpos(php_sapi_name(), 'cgi') !== false) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];

            //  a ? is part of $conf['site']['frontScriptName'] and REQUEST_URI has more info
            } elseif ((strlen($_SERVER['REQUEST_URI']) &gt; strlen($_SERVER['PHP_SELF'])
                    &amp;&amp; strstr($_SERVER['REQUEST_URI'], '?')
                    &amp;&amp; !isset($conf['setup']))) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];

            // we don't want to have index.php in our url, so REQUEST_URI as more info
            } elseif ($conf['site']['frontScriptName'] == false) {
                $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'];
            } else {
                //  do nothing, PHP_SELF is valid
            }

        //  it's IIS
        } else {
            $frontScriptName = is_null($conf) ? 'index.php' : $conf['site']['frontScriptName'];
            if (substr($_SERVER['SCRIPT_NAME'], -1, 1) != substr($frontScriptName, -1, 1)) {
                $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] . '?' . @$_SERVER['QUERY_STRING'];
            } else {
                $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] . @$_SERVER['QUERY_STRING'];
            }

        }
    }
</code>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10713</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Fri, 11 Nov 2005 19:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10713</guid>
		<description>Hi Gaetano - if you're willing to publish that list, a good place might be on this PHP wiki: http://wiki.cc/php/Main_Page e.g. http://wiki.cc/php/SAPI</description>
		<content:encoded><![CDATA[<p>Hi Gaetano - if you&#8217;re willing to publish that list, a good place might be on this PHP wiki: <a href="http://wiki.cc/php/Main_Page" rel="nofollow">http://wiki.cc/php/Main_Page</a> e.g. <a href="http://wiki.cc/php/SAPI" rel="nofollow">http://wiki.cc/php/SAPI</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Gaetano Giunta</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10676</link>
		<dc:creator>Gaetano Giunta</dc:creator>
		<pubDate>Thu, 10 Nov 2005 14:06:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10676</guid>
		<description>imho, the best (only?) solution to this age-old problem would be to put up a cheat sheet with a complete list of all global vars (not only $_SERVER) for all combinations of webserver/php api, highlighting those values that differ from setup to setup.
I have a preliminary table (in excel format) that I can mail to anyone interested.
Contact g i u n t a . g a e t a n o at sea-aeroportimilano dot it
btw: koivi.com is down at the moment...</description>
		<content:encoded><![CDATA[<p>imho, the best (only?) solution to this age-old problem would be to put up a cheat sheet with a complete list of all global vars (not only $_SERVER) for all combinations of webserver/php api, highlighting those values that differ from setup to setup.<br />
I have a preliminary table (in excel format) that I can mail to anyone interested.<br />
Contact g i u n t a . g a e t a n o at sea-aeroportimilano dot it<br />
btw: koivi.com is down at the moment&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10673</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Thu, 10 Nov 2005 11:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10673</guid>
		<description>&lt;blockquote&gt;
REQUEST_URI
SCRIPT_FILENAME
are two things that stand out to me that definitely work in IIS6. I’m not sure about the rest of the list.
&lt;/blockquote&gt;

That's interesting to hear. I guess more detail is required that that table provides.

&lt;blockquote&gt;
Note that this has very little to do with PHP. $_SERVER, as its name implies, tells you the variables set by the web server. The differences all lie in the different web server implementations out there.
&lt;/blockquote&gt;

Very true.

But what's the approach for those trying to develop scripts which run "anywhere" and may not have time / resources to be able to test against all possible SAPI's? 

Two particular things that are helpful to have - the path / filename of the script where execution began, available in a global form (i.e. not __FILE__) and the full (or at least relative to web root) requested URL. If these were available in a form that was invariant under any SAPI, life would be easier for people doing "frameworky" stuff.

Other SAPI independent derivations from there would be nice to have (e.g. if the request is "http://example.com/index.php/foo/bar?x=y" that you can easily get access to "http://example.com/index.php" "/foo/bar?x=y") but these can also be resolve in PHP given the first two.

&lt;blockquote&gt;
what about $_server[’script_name’]
&lt;/blockquote&gt;

Again with PHP as a CGI, this gets populated with the name of the CGI binary, not the file being executed by the binary.</description>
		<content:encoded><![CDATA[<blockquote><p>
REQUEST_URI<br />
SCRIPT_FILENAME<br />
are two things that stand out to me that definitely work in IIS6. I’m not sure about the rest of the list.
</p></blockquote>
<p>That&#8217;s interesting to hear. I guess more detail is required that that table provides.</p>
<blockquote><p>
Note that this has very little to do with PHP. $_SERVER, as its name implies, tells you the variables set by the web server. The differences all lie in the different web server implementations out there.
</p></blockquote>
<p>Very true.</p>
<p>But what&#8217;s the approach for those trying to develop scripts which run &#8220;anywhere&#8221; and may not have time / resources to be able to test against all possible SAPI&#8217;s? </p>
<p>Two particular things that are helpful to have - the path / filename of the script where execution began, available in a global form (i.e. not __FILE__) and the full (or at least relative to web root) requested URL. If these were available in a form that was invariant under any SAPI, life would be easier for people doing &#8220;frameworky&#8221; stuff.</p>
<p>Other SAPI independent derivations from there would be nice to have (e.g. if the request is &#8220;http://example.com/index.php/foo/bar?x=y&#8221; that you can easily get access to &#8220;http://example.com/index.php&#8221; &#8220;/foo/bar?x=y&#8221;) but these can also be resolve in PHP given the first two.</p>
<blockquote><p>
what about $_server[’script_name’]
</p></blockquote>
<p>Again with PHP as a CGI, this gets populated with the name of the CGI binary, not the file being executed by the binary.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dtra</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10671</link>
		<dc:creator>dtra</dc:creator>
		<pubDate>Thu, 10 Nov 2005 10:25:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10671</guid>
		<description>sorry if this is stupid, but what about $_server['script_name']?</description>
		<content:encoded><![CDATA[<p>sorry if this is stupid, but what about $_server[&#8217;script_name&#8217;]?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: foo</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10660</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Wed, 09 Nov 2005 23:11:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10660</guid>
		<description>Note that this has very little to do with PHP.  $_SERVER, as its name implies, tells you the variables set by the web server.  The differences all lie in the different web server implementations out there.</description>
		<content:encoded><![CDATA[<p>Note that this has very little to do with PHP.  $_SERVER, as its name implies, tells you the variables set by the web server.  The differences all lie in the different web server implementations out there.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Kymnto Blog &#187; La variabile superglobal $_SERVER in IIS e Apache</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10659</link>
		<dc:creator>Kymnto Blog &#187; La variabile superglobal $_SERVER in IIS e Apache</dc:creator>
		<pubDate>Wed, 09 Nov 2005 21:06:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10659</guid>
		<description>[...] Veramente interessante. Ah, di questo argomento se ne parla anche su SitePoint Blogs.  [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Veramente interessante. Ah, di questo argomento se ne parla anche su SitePoint Blogs.  [&#8230;]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: VodkaFish</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10658</link>
		<dc:creator>VodkaFish</dc:creator>
		<pubDate>Wed, 09 Nov 2005 21:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10658</guid>
		<description>That chart may or may not be useful.  IIS 5.1 is for Windows XP Professional, not really a "real world" example IMO.

REQUEST_URI
SCRIPT_FILENAME
are two things that stand out to me that definitely work in IIS6.  I'm not sure about the rest of the list.</description>
		<content:encoded><![CDATA[<p>That chart may or may not be useful.  IIS 5.1 is for Windows XP Professional, not really a &#8220;real world&#8221; example IMO.</p>
<p>REQUEST_URI<br />
SCRIPT_FILENAME<br />
are two things that stand out to me that definitely work in IIS6.  I&#8217;m not sure about the rest of the list.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: chris ward</title>
		<link>http://www.sitepoint.com/blogs/2005/11/09/php-server-api-differences/#comment-10648</link>
		<dc:creator>chris ward</dc:creator>
		<pubDate>Wed, 09 Nov 2005 15:03:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1293#comment-10648</guid>
		<description>PHP_SELF is the method i've been using for requesting the URI string.

What perplexes me more, is when I try to figure out the visitor's true IP address, and not their proxy.

A quick tip is to make a call to php_info()! It's a good way to see the initial results of all the server variables at a glance.

Even more handy when you're using mod_rewrite and things start to get a bit confusing!</description>
		<content:encoded><![CDATA[<p>PHP_SELF is the method i&#8217;ve been using for requesting the URI string.</p>
<p>What perplexes me more, is when I try to figure out the visitor&#8217;s true IP address, and not their proxy.</p>
<p>A quick tip is to make a call to php_info()! It&#8217;s a good way to see the initial results of all the server variables at a glance.</p>
<p>Even more handy when you&#8217;re using mod_rewrite and things start to get a bit confusing!</p>]]></content:encoded>
	</item>
</channel>
</rss>
