<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The PATH_TRANSLATED blues</title>
	<atom:link href="http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Mon, 23 Nov 2009 05:23:27 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: DW</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-38922</link>
		<dc:creator>DW</dc:creator>
		<pubDate>Tue, 18 Jul 2006 22:21:33 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-38922</guid>
		<description>getcwd() is the solution I chose :)</description>
		<content:encoded><![CDATA[<p>getcwd() is the solution I chose :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rajesh</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-31237</link>
		<dc:creator>Rajesh</dc:creator>
		<pubDate>Mon, 19 Jun 2006 20:30:36 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-31237</guid>
		<description>I know at least one place where a programmer has used 
eval(file_get_contents(&#039;some_script.php&#039;)) to include a file.
I don&#039;t exactly remember why but it solved a nice security
problem. 

The array_shift(get_included_files()) won&#039;t work in this case 
either.</description>
		<content:encoded><![CDATA[<p>I know at least one place where a programmer has used<br />
eval(file_get_contents(&#8217;some_script.php&#8217;)) to include a file.<br />
I don&#8217;t exactly remember why but it solved a nice security<br />
problem. </p>
<p>The array_shift(get_included_files()) won&#8217;t work in this case<br />
either.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: cyngon</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-447</link>
		<dc:creator>cyngon</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-447</guid>
		<description>&lt;p&gt;Just wondering:  Are either of those techniques affected if you use mod_rewrite and the address they types into the browser isn&#039;t necessarily the address they end up at?&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Just wondering:  Are either of those techniques affected if you use mod_rewrite and the address they types into the browser isn&#8217;t necessarily the address they end up at?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-448</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-448</guid>
		<description>&lt;p&gt;I use mod_rewrite heavily, which has a similar effect in that you can&#039;t trust pathnames (although $_SERVER[PHP_SELF] may still work). &lt;/p&gt;

&lt;p&gt;Anyway, my solution is to define a set of variables regarding paths (normally http path and file path, sometimes https), so the only known path necessary is the core included file; everything can use absolute paths using the core include&#039;s defined vars. Example:&lt;br /&gt;
 $path[&#039;http&#039;] = /var/www/sitex;&lt;br /&gt;
 include($path[&#039;http&#039;].&#039;/includes/x.php&#039;);&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I use mod_rewrite heavily, which has a similar effect in that you can&#8217;t trust pathnames (although $_SERVER[PHP_SELF] may still work). </p>
<p>Anyway, my solution is to define a set of variables regarding paths (normally http path and file path, sometimes https), so the only known path necessary is the core included file; everything can use absolute paths using the core include&#8217;s defined vars. Example:<br />
 $path['http'] = /var/www/sitex;<br />
 include($path['http'].&#8217;/includes/x.php&#8217;);</p>]]></content:encoded>
	</item>
	<item>
		<title>By: KillAllDash9</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-449</link>
		<dc:creator>KillAllDash9</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-449</guid>
		<description>&lt;p&gt;It&#039;s not super elegant, but you could start every script with:&lt;/p&gt;

&lt;p&gt;if (!defined(&#039;MAIN_EXEC_DIR&#039;)) define(&#039;MAIN_EXEC_DIR&#039;, dirname(__FILE__));&lt;/p&gt;

&lt;p&gt;Then MAIN_EXEC_DIR would always contain the information you are looking for. Certainly, it&#039;s a pain to have to put this in every file, though.&lt;/p&gt;

&lt;p&gt;Another option is to actually make use of the include_path INI setting, which can also be altered at run time via ini_set().&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>It&#8217;s not super elegant, but you could start every script with:</p>
<p>if (!defined(&#8217;MAIN_EXEC_DIR&#8217;)) define(&#8217;MAIN_EXEC_DIR&#8217;, dirname(__FILE__));</p>
<p>Then MAIN_EXEC_DIR would always contain the information you are looking for. Certainly, it&#8217;s a pain to have to put this in every file, though.</p>
<p>Another option is to actually make use of the include_path INI setting, which can also be altered at run time via ini_set().</p>]]></content:encoded>
	</item>
	<item>
		<title>By: cagrET</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-450</link>
		<dc:creator>cagrET</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-450</guid>
		<description>&lt;p&gt;I don&#039;t have php as cgi so cannot test it, but maybe this will work (only PHP 4 &gt;= 4.3.0, PHP 5):&lt;/p&gt;

&lt;code&gt;
&lt;?php
// common.inc.php

if (function_exists(&#039;debug_backtrace&#039;)) {
    $tmp = debug_backtrace();
    $_SERVER[&#039;PATH_TRANSLATED&#039;] = $tmp[0][&#039;file&#039;];
}
?&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I don&#8217;t have php as cgi so cannot test it, but maybe this will work (only PHP 4 >= 4.3.0, PHP 5):</p>
<code>
< ?php
// common.inc.php

if (function_exists('debug_backtrace')) {
    $tmp = debug_backtrace();
    $_SERVER['PATH_TRANSLATED'] = $tmp[0]['file'];
}
?></code>]]></content:encoded>
	</item>
	<item>
		<title>By: cagrET</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-451</link>
		<dc:creator>cagrET</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-451</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;Code within WACT then needs to be able to determine where myscript.php is located in the filesystem, so that a users templates, for example, can be located relative to myscript.php&#039;s path.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
Btw.&lt;br /&gt;
Why do you need $_SERVER[&#039;PATH_TRANSLATED&#039;] for this ?&lt;br /&gt;
If the script is called like this: http://domain.foo/some/myscript.php, template is here: /some/templates/example.tpl, relative path to template: &#039;templates/example.tpl&#039;, why can&#039;t you just do: require &#039;templates/example.tpl&#039; ?&lt;/p&gt;

&lt;p&gt;Or maybe this:&lt;/p&gt;

&lt;p&gt;require $_SERVER[&#039;DOCUMENT_ROOT&#039;] . dirname($_SERVER[&#039;PHP_SELF&#039;]) . &quot;/templates/example.tpl&quot;;&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<p>Code within WACT then needs to be able to determine where myscript.php is located in the filesystem, so that a users templates, for example, can be located relative to myscript.php&#8217;s path.</p>
</blockquote>
</p><p>
Btw.<br />
Why do you need $_SERVER['PATH_TRANSLATED'] for this ?<br />
If the script is called like this: <a href="http://domain.foo/some/myscript.php" rel="nofollow">http://domain.foo/some/myscript.php</a>, template is here: /some/templates/example.tpl, relative path to template: &#8216;templates/example.tpl&#8217;, why can&#8217;t you just do: require &#8216;templates/example.tpl&#8217; ?</p>
<p>Or maybe this:</p>
<p>require $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . &#8220;/templates/example.tpl&#8221;;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Demian Turner</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-452</link>
		<dc:creator>Demian Turner</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-452</guid>
		<description>&lt;p&gt;Perhaps this is helpful - Seagull dynamically determines the the script location on the filesystem and the web root of the calling URL.  To do this each page execution first loads an init file:&lt;/p&gt;

&lt;p&gt;http://muse23.com/cgi-bin/cvsweb.cgi/seagull/init.php?rev=1.84&amp;content-type=text/x-cvsweb-markup&lt;/p&gt;

&lt;p&gt;cheers&lt;/p&gt;

&lt;p&gt;Demian&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Perhaps this is helpful &#8211; Seagull dynamically determines the the script location on the filesystem and the web root of the calling URL.  To do this each page execution first loads an init file:</p>
<p><a href="http://muse23.com/cgi-bin/cvsweb.cgi/seagull/init.php?rev=1.84&#038;content-type=text/x-cvsweb-markup" rel="nofollow">http://muse23.com/cgi-bin/cvsweb.cgi/seagull/init.php?rev=1.84&#038;content-type=text/x-cvsweb-markup</a></p>
<p>cheers</p>
<p>Demian</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-453</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-453</guid>
		<description>&lt;p&gt;[QUOTE=cyngon]Just wondering:  Are either of those techniques affected if you use mod_rewrite and the address they types into the browser isn&#039;t necessarily the address they end up at?[/QUOTE]&lt;/p&gt;

&lt;p&gt;Good question. Not sure. Will explore that shortly.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>[QUOTE=cyngon]Just wondering:  Are either of those techniques affected if you use mod_rewrite and the address they types into the browser isn&#8217;t necessarily the address they end up at?[/QUOTE]</p>
<p>Good question. Not sure. Will explore that shortly.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/06/08/the-path_translated-blues/comment-page-1/#comment-454</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1393452010#comment-454</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code lang=&quot;php&quot;&gt;
if (!defined(&#039;MAIN_EXEC_DIR&#039;)) define(&#039;MAIN_EXEC_DIR&#039;, dirname(__FILE__));&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;I guess that will be the last resort. Would be a shame because it requires WACT users to define it (nice when it could happen automatically).&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code lang=&quot;php&quot;&gt;
&lt;?php
// common.inc.php

if (function_exists(&#039;debug_backtrace&#039;)) {
    $tmp = debug_backtrace();
    $_SERVER[&#039;PATH_TRANSLATED&#039;] = $tmp[0][&#039;file&#039;];
}
?&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;Good point. OK it&#039;s PHP 4.3.0 only but perhaps we can use that inside some code which makes various guesses (using SCRIPT_FILENAME, PATH_TRANSLATED and any thing that might be useable).&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
why can&#039;t you just do: require &#039;templates/example.tpl&#039; ?&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;That &lt;i&gt;may&lt;/i&gt; be an option to explore. We need the path for various file operations (e.g. writing a &quot;compiled&quot; template script) but fopen also supports using the include_path - good point.&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
$_SERVER[&#039;DOCUMENT_ROOT&#039;] . dirname($_SERVER[&#039;PHP_SELF&#039;])&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Possibly&lt;/i&gt; - think those are also somewhat subject to the PHP SAPI you&#039;re using but may be useful if we&#039;re doing some sort of detection.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<code lang="php">
if (!defined('MAIN_EXEC_DIR')) define('MAIN_EXEC_DIR', dirname(__FILE__));</code>
</blockquote>
</p><p>I guess that will be the last resort. Would be a shame because it requires WACT users to define it (nice when it could happen automatically).</p>
<p>
<blockquote>
<code lang="php">
< ?php
// common.inc.php

if (function_exists('debug_backtrace')) {
    $tmp = debug_backtrace();
    $_SERVER['PATH_TRANSLATED'] = $tmp[0]['file'];
}
?></code>
</blockquote>
</p><p>Good point. OK it&#8217;s PHP 4.3.0 only but perhaps we can use that inside some code which makes various guesses (using SCRIPT_FILENAME, PATH_TRANSLATED and any thing that might be useable).</p>
<p>
<blockquote>
<p>
why can&#8217;t you just do: require &#8216;templates/example.tpl&#8217; ?
</p>
</blockquote>
</p><p>That <i>may</i> be an option to explore. We need the path for various file operations (e.g. writing a &#8220;compiled&#8221; template script) but fopen also supports using the include_path &#8211; good point.</p>
<p>
<blockquote>
<p>
$_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF'])
</p>
</blockquote>
</p><p><i>Possibly</i> &#8211; think those are also somewhat subject to the PHP SAPI you&#8217;re using but may be useful if we&#8217;re doing some sort of detection.</p>]]></content:encoded>
	</item>
</channel>
</rss>
