0

I have been learning php recently and i found this strange statement that i tried to figure out but did not understand it well. This is the URI that i found

    <?php 
        $datei = file("http://www.abc.de/cms/index.php/pps.html");
        foreach($datei AS $stellenangebote)
        {
           echo $stellenangebote;
        }
    ?>

Now the question that i am trying to understand is that how come it reach the .html page while it has .php before it ? And if this is a technique then What is it's name ? And why would i use such style ?

2 Answers2

0

This is an Apache thing called PathInfo. It's activated if you have set AcceptPathInfo, which it usually is by default. You can then access the part after the file name through $_SERVER['PATH_INFO'].

There's more information available in the answers to "What exactly is PATH_INFO in PHP?"

Community
  • 1
  • 1
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
0

This technique is used to create a single entry point to the application. This allows you to control the flow of you application - all requests are processed by index.php, so you have one place to load classes, initialize objects etc.

Most modern php based sites will use this technique (it is central to the MVC paradigm used in the vast majority of modern web frameworks), though many hide the actual index.php file in the ur using Apache mod_rewrite or similar for other webservers.

As mentioned by fiskfisk, this can be achieved by accessing the request path. A simple example used to load files from a non web accessible location for authorized users:

<?php
$path = $_SERVER['PATH_INFO'];
//if user is authorized, include file from OUTSIDE of webroot
if(isset($_SESSION['auth']) && ($_SESSION['auth'] > 3)){
    include '../' . $path;
}else{
    die('you are not authorized to see this file');
}

As to the official name for this technique, i am not sure, but google "php single entry point" or "php route through index" should help.

Steve
  • 20,703
  • 5
  • 41
  • 67