Documentation TYPO3 par Ameos

incfile.php

00001 <?php
00002         // This checks for my own IP at home. You can just remove the if-statement.
00003 if (1==0 || (substr($_SERVER['REMOTE_ADDR'],0,7)!='192.168' && $_SERVER['REMOTE_ADDR']!='127.0.0.1'))   {
00004         die('In the source distribution of TYPO3, this script is disabled by a die() function call.<br/><b>Fix:</b> Open the file misc/phpcheck/incfile.php and remove/out-comment the line that outputs this message!');
00005 }
00006 
00007 SetCookie("test_script_cookie", "Cookie Value!", 0, "/");
00008 
00009 
00010 class t3lib_div {
00011         function trimExplode($delim, $string, $onlyNonEmptyValues=0)    {
00012                 // This explodes a comma-list into an array where the values are parsed through trim();
00013                 $temp = explode($delim,$string);
00014                 $newtemp=array();
00015                 while(list($key,$val)=each($temp))      {
00016                         if (!$onlyNonEmptyValues || strcmp("",trim($val)))      {
00017                                 $newtemp[]=trim($val);
00018                         }
00019                 }
00020                 reset($newtemp);
00021                 return $newtemp;
00022         }
00023         function dirname($path) {
00024                 $p=t3lib_div::revExplode("/",$path,2);
00025                 return count($p)==2?$p[0]:"";
00026         }
00027         function revExplode($delim, $string, $count=0)  {
00028                 $temp = explode($delim,strrev($string),$count);
00029                 while(list($key,$val)=each($temp))      {
00030                         $temp[$key]=strrev($val);
00031                 }
00032                 $temp=array_reverse($temp);
00033                 reset($temp);
00034                 return $temp;
00035         }
00036 
00046         function getIndpEnv($getEnvName)        {
00047                 global $HTTP_SERVER_VARS;
00048                 /*
00049                         Conventions:
00050                         output from parse_url():
00051                         URL:    http://username:password@192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1
00052                             [scheme] => 'http'
00053                             [user] => 'username'
00054                             [pass] => 'password'
00055                             [host] => '192.168.1.4'
00056                                 [port] => '8080'
00057                             [path] => '/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/'
00058                             [query] => 'arg1,arg2,arg3&p1=parameter1&p2[key]=value'
00059                             [fragment] => 'link1'
00060 
00061                                 Further definition: [path_script] = '/typo3/32/temp/phpcheck/index.php'
00062                                                                         [path_dir] = '/typo3/32/temp/phpcheck/'
00063                                                                         [path_info] = '/arg1/arg2/arg3/'
00064                                                                         [path] = [path_script/path_dir][path_info]
00065 
00066 
00067                         Keys supported:
00068 
00069                         URI______:
00070                                 REQUEST_URI             =       [path]?[query]          = /typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value
00071                                 HTTP_HOST               =       [host][:[port]]         = 192.168.1.4:8080
00072                                 SCRIPT_NAME             =       [path_script]++         = /typo3/32/temp/phpcheck/index.php             // NOTICE THAT SCRIPT_NAME will return the php-script name ALSO. [path_script] may not do that (eg. '/somedir/' may result in SCRIPT_NAME '/somedir/index.php')!
00073                                 PATH_INFO               =       [path_info]                     = /arg1/arg2/arg3/
00074                                 QUERY_STRING    =       [query]                         = arg1,arg2,arg3&p1=parameter1&p2[key]=value
00075                                 HTTP_REFERER    =       [scheme]://[host][:[port]][path]        = http://192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value
00076                                                                                 (Notice: NO username/password + NO fragment)
00077 
00078                         CLIENT____:
00079                                 REMOTE_ADDR             =       (client IP)
00080                                 REMOTE_HOST             =       (client host)
00081                                 HTTP_USER_AGENT =       (client user agent)
00082                                 HTTP_ACCEPT_LANGUAGE    = (client accept language)
00083 
00084                         SERVER____:
00085                                 SCRIPT_FILENAME =       Absolute filename of script             (Differs between windows/unix). On windows 'C:\\blabla\\blabl\\' will be converted to 'C:/blabla/blabl/'
00086 
00087                         Special extras:
00088                                 TYPO3_HOST_ONLY =               [host]                  = 192.168.1.4
00089                                 TYPO3_PORT              =               [port]                  = 8080 (blank if 80, taken from host value)
00090                                 TYPO3_REQUEST_HOST =    [scheme]://[host][:[port]]
00091                                 TYPO3_REQUEST_URL =             [scheme]://[host][:[port]][path]?[query]        (sheme will by default be 'http' until we can detect if it's https -
00092                                 TYPO3_REQUEST_SCRIPT =  [scheme]://[host][:[port]][path_script]
00093                                 TYPO3_REQUEST_DIR =             [scheme]://[host][:[port]][path_dir]
00094                                 TYPO3_SITE_URL =                [scheme]://[host][:[port]][path_dir] of the TYPO3 website
00095                                 TYPO3_DOCUMENT_ROOT     =       Absolute path of root of documents:     TYPO3_DOCUMENT_ROOT.SCRIPT_NAME = SCRIPT_FILENAME (typically)
00096 
00097                         Notice: [fragment] is apparently NEVER available to the script!
00098 
00099 
00100                         Testing suggestions:
00101                         - Output all the values.
00102                         - In the script, make a link to the script it self, maybe add some parameters and click the link a few times so HTTP_REFERER is seen
00103                         - ALSO TRY the script from the ROOT of a site (like 'http://www.mytest.com/' and not 'http://www.mytest.com/test/' !!)
00104 
00105                 */
00106 
00107 #               if ($getEnvName=='HTTP_REFERER')        return '';
00108                 switch((string)$getEnvName)     {
00109                         case 'SCRIPT_NAME':
00110                                 return php_sapi_name()=='cgi' ? $HTTP_SERVER_VARS['PATH_INFO'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
00111                         break;
00112                         case 'SCRIPT_FILENAME':
00113                                 return str_replace('//','/', str_replace('\\','/', php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ? $HTTP_SERVER_VARS['PATH_TRANSLATED']:$HTTP_SERVER_VARS['SCRIPT_FILENAME']));
00114                         break;
00115                         case 'REQUEST_URI':
00116                                 // Typical application of REQUEST_URI is return urls, forms submitting to itselt etc. Eg:       returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))
00117                                 if (!$HTTP_SERVER_VARS['REQUEST_URI'])  {       // This is for ISS/CGI which does not have the REQUEST_URI available.
00118                                         return '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
00119                                                 ($HTTP_SERVER_VARS['QUERY_STRING']?'?'.$HTTP_SERVER_VARS['QUERY_STRING']:'');
00120                                 } else return $HTTP_SERVER_VARS['REQUEST_URI'];
00121                         break;
00122                         case 'PATH_INFO':
00123                                         // $HTTP_SERVER_VARS['PATH_INFO']!=$HTTP_SERVER_VARS['SCRIPT_NAME'] is necessary because some servers (Windows/CGI) are seen to set PATH_INFO equal to script_name
00124                                         // Further, there must be at least one '/' in the path - else the PATH_INFO value does not make sense.
00125                                         // IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers, then 'php_sapi_name()=='cgi'' might be a better check. Right now strcmp($HTTP_SERVER_VARS['PATH_INFO'],t3lib_div::getIndpEnv('SCRIPT_NAME')) will always return false for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO because of php_sapi_name()=='cgi' (see above)
00126 //                              if (strcmp($HTTP_SERVER_VARS['PATH_INFO'],t3lib_div::getIndpEnv('SCRIPT_NAME')) && count(explode('/',$HTTP_SERVER_VARS['PATH_INFO']))>1)        {
00127                                 if (php_sapi_name()!='cgi')     {
00128                                         return $HTTP_SERVER_VARS['PATH_INFO'];
00129                                 } else return '';
00130                         break;
00131                                 // These are let through without modification
00132                         case 'REMOTE_ADDR':
00133                         case 'REMOTE_HOST':
00134                         case 'HTTP_REFERER':
00135                         case 'HTTP_HOST':
00136                         case 'HTTP_USER_AGENT':
00137                         case 'HTTP_ACCEPT_LANGUAGE':
00138                         case 'QUERY_STRING':
00139                                 return $HTTP_SERVER_VARS[$getEnvName];
00140                         break;
00141                         case 'TYPO3_DOCUMENT_ROOT':
00142                                 // Some CGI-versions (LA13CGI) and mod-rewrite rules on MODULE versions will deliver a 'wrong' DOCUMENT_ROOT (according to our description). Further various aliases/mod_rewrite rules can disturb this as well.
00143                                 // Therefore the DOCUMENT_ROOT is now always calculated as the SCRIPT_FILENAME minus the end part shared with SCRIPT_NAME.
00144                                 $SFN = t3lib_div::getIndpEnv('SCRIPT_FILENAME');
00145                                 $SN_A = explode('/',strrev(t3lib_div::getIndpEnv('SCRIPT_NAME')));
00146                                 $SFN_A = explode('/',strrev($SFN));
00147                                 $acc=array();
00148                                 while(list($kk,$vv)=each($SN_A))        {
00149                                         if (!strcmp($SFN_A[$kk],$vv))   {
00150                                                 $acc[]=$vv;
00151                                         } else break;
00152                                 }
00153                                 $commonEnd=strrev(implode('/',$acc));
00154                                 if (strcmp($commonEnd,''))              $DR = substr($SFN,0,-(strlen($commonEnd)+1));
00155                                 return $DR;
00156                         break;
00157                         case 'TYPO3_HOST_ONLY':
00158                                 $p=explode(':',$HTTP_SERVER_VARS['HTTP_HOST']);
00159                                 return $p[0];
00160                         break;
00161                         case 'TYPO3_PORT':
00162                                 $p=explode(':',$HTTP_SERVER_VARS['HTTP_HOST']);
00163                                 return $p[1];
00164                         break;
00165                         case 'TYPO3_REQUEST_HOST':
00166                                 return 'http'.($HTTP_SERVER_VARS['SSL_SESSION_ID']?'s':'').'://'.       // I hope this: ($HTTP_SERVER_VARS['SSL_SESSION_ID']?'s':'') - is sufficient to detect https...
00167                                         $HTTP_SERVER_VARS['HTTP_HOST'];
00168                         break;
00169                         case 'TYPO3_REQUEST_URL':
00170                                 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('REQUEST_URI');
00171                         break;
00172                         case 'TYPO3_REQUEST_SCRIPT':
00173                                 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('SCRIPT_NAME');
00174                         break;
00175                         case 'TYPO3_REQUEST_DIR':
00176                                 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
00177                         break;
00178                         case 'TYPO3_SITE_URL':
00179                                 if (defined('PATH_thisScript') && defined('PATH_site')) {
00180                                         $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
00181                                         $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
00182                                         $siteUrl = substr($url,0,-strlen($lPath));
00183                                         if (substr($siteUrl,-1)!='/')   $siteUrl.='/';
00184                                         return $siteUrl;
00185                                 } else return '';
00186 
00187                         break;
00188                         case '_ARRAY':
00189                                 $out=array();
00190                                         // Here, list ALL possible keys to this function for debug display.
00191                                 $envTestVars = t3lib_div::trimExplode(',','
00192                                         HTTP_HOST,
00193                                         TYPO3_HOST_ONLY,
00194                                         TYPO3_PORT,
00195                                         PATH_INFO,
00196                                         QUERY_STRING,
00197                                         REQUEST_URI,
00198                                         HTTP_REFERER,
00199                                         TYPO3_REQUEST_HOST,
00200                                         TYPO3_REQUEST_URL,
00201                                         TYPO3_REQUEST_SCRIPT,
00202                                         TYPO3_REQUEST_DIR,
00203                                         TYPO3_SITE_URL,
00204                                         SCRIPT_NAME,
00205                                         TYPO3_DOCUMENT_ROOT,
00206                                         SCRIPT_FILENAME,
00207                                         REMOTE_ADDR,
00208                                         REMOTE_HOST,
00209                                         HTTP_USER_AGENT,
00210                                         HTTP_ACCEPT_LANGUAGE',1);
00211                                 reset($envTestVars);
00212                                 while(list(,$v)=each($envTestVars))     {
00213                                         $out[$v]=t3lib_div::getIndpEnv($v);
00214                                 }
00215                                 reset($out);
00216                                 return $out;
00217                         break;
00218                 }
00219         }
00220 
00221 }
00222 
00223         function view_array($array_in)  {
00224                 // Returns HTML-code, which is a visual representation of a multidimensional array
00225                 // use t3lib_div::print_array() in order to print an array
00226                 // Returns false if $array_in is not an array
00227                 if (is_array($array_in))        {
00228                         $result='<table border=1 cellpadding=1 cellspacing=0 bgcolor=white>';
00229                         if (!count($array_in))  {$result.= '<tr><td><font face="Verdana,Arial" size="1"><b>'.HTMLSpecialChars("EMPTY!").'</b></font></td></tr>';}
00230                         while (list($key,$val)=each($array_in)) {
00231                                 $result.= '<tr><td><font face="Verdana,Arial" size="1">'.HTMLSpecialChars($key).'</font></td><td>';
00232                                 if (is_array($array_in[$key]))  {
00233                                         $result.=t3lib_div::view_array($array_in[$key]);
00234                                 } else
00235                                         $result.= '<font face="Verdana,Arial" size="1" color=red>'.nl2br(HTMLSpecialChars($val)).'<BR></font>';
00236                                 $result.= '</td></tr>';
00237                         }
00238                         $result.= '</table>';
00239                 } else  {
00240                         $result  = false;
00241                 }
00242                 return $result;
00243         }
00244         function debug($array_in)       {
00245                 // Prints an array
00246                 echo view_array($array_in);
00247         }
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264         error_reporting (E_ALL ^ E_NOTICE);
00265 
00266 define("TYPO3_OS", stristr(PHP_OS,"win")&&!stristr(PHP_OS,"darwin")?"WIN":"");
00267 /*
00268 define("PATH_thisScript",
00269         TYPO3_OS=="WIN" ?
00270         str_replace('//','/',str_replace('\\','/', $HTTP_SERVER_VARS["PATH_TRANSLATED"]?$HTTP_SERVER_VARS["PATH_TRANSLATED"]:getenv("PATH_TRANSLATED"))) :
00271         (php_sapi_name()=="cgi"?(getenv("PATH_TRANSLATED")?getenv("PATH_TRANSLATED"):getenv("SCRIPT_FILENAME")):$HTTP_SERVER_VARS["PATH_TRANSLATED"])
00272 );
00273         */
00274 
00275 define("PATH_thisScript",str_replace('//','/', str_replace('\\','/', php_sapi_name()=="cgi"||php_sapi_name()=="isapi" ? $HTTP_SERVER_VARS["PATH_TRANSLATED"]:$HTTP_SERVER_VARS["SCRIPT_FILENAME"])));
00276 define('PATH_site', dirname(PATH_thisScript).'/');
00277 
00278 
00279 if (count($_GET) || $_SERVER["HTTP_REFERER"])   {
00280         # KOMPENSATED:
00281         echo "<H3>t3lib_div::getIndpEnv()</H3><p>These are 'system variables' returned from t3lib_div::getIndpEnv() and should be universal for any server configuration:</p>";
00282         debug(t3lib_div::getIndpEnv("_ARRAY"));
00283 
00284         debug(array(
00285                 "PHP_OS"=>PHP_OS,
00286                 "TYPO3_OS"=>TYPO3_OS,
00287                 "PATH_thisScript"=>PATH_thisScript,
00288                 "php_sapi_name()" => php_sapi_name()
00289         ));
00290 
00291 
00292 
00293 
00294         ##debug(parse_url("http://admin:palindrom@192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/index.php?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1"));
00295 
00296 
00297         echo "<H3>Raw values</H3><p>These are the raw 'system variables' returned from getenv(), HTTP_SERVER_VARS, HTTP_ENV_VARS etc. These are displayed here so we can find the right values via this testscript to map to with t3lib_div::getIndpEnv()</p>";
00298         $envTestVars = explode(",","REQUEST_URI,REMOTE_ADDR,REMOTE_HOST,PATH_INFO,SCRIPT_NAME,SCRIPT_FILENAME,HTTP_HOST,HTTP_USER_AGENT,HTTP_ACCEPT_ENCODING,HTTP_REFERER,QUERY_STRING");
00299         $lines=array();
00300                 $lines[] = '<tr bgcolor="#eeeeee">
00301                         <td>Key</td>
00302                         <td nowrap>getenv()</td>
00303                         <td nowrap>HTTP_SERVER_VARS</td>
00304                         <td nowrap>_SERVER</td>
00305                         <td nowrap>HTTP_ENV_VARS</td>
00306                         <td nowrap>_ENV</td>
00307                 </tr>';
00308         while(list(,$v)=each($envTestVars))     {
00309                 $lines[] = '<tr>
00310                         <td bgcolor="#eeeeee">'.htmlspecialchars($v).'</td>
00311                         <td nowrap>'.htmlspecialchars(getenv($v)).'&nbsp;</td>
00312                         <td nowrap>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"][$v]).'&nbsp;</td>
00313                         <td nowrap>'.htmlspecialchars($GLOBALS["_SERVER"][$v]).'&nbsp;</td>
00314                         <td nowrap>'.htmlspecialchars($GLOBALS["HTTP_ENV_VARS"][$v]).'&nbsp;</td>
00315                         <td nowrap>'.htmlspecialchars($GLOBALS["_ENV"][$v]).'&nbsp;</td>
00316                 </tr>';
00317         }
00318         echo '<table border=1 style="font-family:verdana; font-size:10px;">'.implode("",$lines).'</table>';
00319 
00320         echo '<table border=1 style="font-family:verdana; font-size:10px;">
00321         <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["DOCUMENT_ROOT"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["DOCUMENT_ROOT"]).'</td></tr>
00322         <tr><td>'.htmlspecialchars('$HTTP_SERVER_VARS["PATH_TRANSLATED"]').'</td><td>'.htmlspecialchars($HTTP_SERVER_VARS["PATH_TRANSLATED"]).'</td></tr>
00323         <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["REDIRECT_URL"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["REDIRECT_URL"]).'</td></tr>
00324         <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]).'</td></tr>
00325         </table>';
00326 
00327 
00328 
00329         echo "Cookie 'test_script_cookie': '<strong>".$HTTP_COOKIE_VARS["test_script_cookie"]."</strong>'<BR>";
00330 
00331 
00332         echo '<HR><a name="link1"></a>';
00333         echo '<div style="border: 1px solid black; padding: 10px 10px 10px 10px;"><h3>What to do now?</h3>
00334                 <p>1) Click this link above once more: <a href="index.php?arg1,arg2,arg3&p1=parameter1&p2[key]='.substr(md5(time()),0,4).'#link1">Go to this page again.</a><BR>
00335                 2) Then save this HTML-page and send it to kasperYYYY@typo3.com with information about 1) which webserver (Apache/ISS), 2) Unix/Windows, 3) CGI or module (ISAPI)<br>
00336                 2a) You might help us find any differences in your values to this <a href="reference.html" target="_blank">reference example</a> by comparing the values before you send the result (thanks).
00337                 <br>
00338                 3) If you are really advanced you try and click the link below here. With CGI-versions of servers it will most likely give an error page. If it does not, please send the output to me as well (save HTML-page and send to kasperYYYY@typo3.com). If you do this PATH_INFO test, please let me know.<br><br>
00339 
00340                 4) For the really, really advanced folks, it might be interesting to see the output if you could place this link in the root of a domain. That means the index.php script will be executed from eg. "http://www.blablabla.com/" and not "http://www.blablabla.com/kaspers_test/" - it can make a difference.<br>
00341                 <br>
00342                 <br>
00343                 I am operating with these categories of servers. <strong>Please identify your configuration and label your email with that "type":</strong><br><br>
00344 
00345                 <table border=1>
00346 <tr bgcolor="#eeeeee">
00347         <td><em>TYPE:</em></td>
00348         <td><em>Description:</em></td>
00349 </tr>
00350 <tr>
00351         <td>WA13CGI</td>
00352         <td>Windows / Apache 1.3.x / CGI</td>
00353 </tr>
00354 <tr>
00355         <td>WA2CGI</td>
00356         <td>Windows / Apache 2.x / CGI</td>
00357 </tr>
00358 <tr>
00359         <td>WA13ISAPI</td>
00360         <td>Windows / Apache 1.3.x / ISAPI-module</td>
00361 </tr>
00362 <tr>
00363         <td>WA2ISAPI</td>
00364         <td>Windows / Apache 2.x / ISAPI-module</td>
00365 </tr>
00366 <tr>
00367         <td>WISS_CGI</td>
00368         <td>Windows / ISS / CGI</td>
00369 </tr>
00370 <tr>
00371         <td>WISS_ISAPI</td>
00372         <td>Windows / ISS / ISAPI-module</td>
00373 </tr>
00374 <tr>
00375         <td>MA13MOD</td>
00376         <td>Mac (Darwin) / Apache 1.3.x / Module</td>
00377 </tr>
00378 <tr>
00379         <td>LA13CGI</td>
00380         <td>Linux / Apache 1.3.x / CGI</td>
00381 </tr>
00382 <tr>
00383         <td>LA2CGI</td>
00384         <td>Linux / Apache 2.x / CGI</td>
00385 </tr>
00386 <tr>
00387         <td>LA13MOD</td>
00388         <td>Linux / Apache 1.3.x / Module</td>
00389 </tr>
00390 <tr>
00391         <td>LA2MOD</td>
00392         <td>Linux / Apache 2.x / Module</td>
00393 </tr>
00394 </table>
00395 
00396 
00397                 </p></div>';
00398         echo '<a href="index.php/arg1/arg2/arg3/#link2" name="link2">Go to this page again (PATH_INFO).</a><BR>';
00399 
00400         phpinfo();
00401 } else {
00402         echo '<a href="index.php?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1" name="link1">Click this link to start the test.</a><BR>';
00403 }
00404 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6