Hey, i dont know how this is called but i have ideas and if it possilbe that someone can help Help me about this:

i have file index.php and 2 folders called: blue, red.
in these 2 folders therse a pages that content the same backgroundcolor as the foloders name.
like in the image:

is that possible to make a query on the index.php that get the content of blue or red.
exmple supose mysite called querytest.com/?q=blue , so the blue content should be shown.

the problem how can i knew that the requsted page that called by user "x" still shown only to that user "x",
mean if some1 else request: querytest.com , he got the default page , not red or blue , but for
who asked for red or blue , its still show the blue or red for that user with the standard link: querytest.com,
or querytest.com/?q=blue or querytest.com/?q=red.

thx so much i searched alreay about mapping urls, but i found it little confused, i dont know if to set something in
cookie or i dont know.

You can with a htaccess redirect, but from what I can tell: wouldn't it be easier to use only one php file and include a different stylesheet?

Hey pritaeas, thx for your responding, but the blue and red it was just to show an exemple, in my real meaning it was about different languages

Hi,

Just to give you a simple example. By the way there are many terminologies used to describe what you want to accomplished. On a lower level, it can be called simple router and simple dispatcher. Some will call this as front controller which is a pattern that implements a router class and a dispatcher class. As the application gets bigger, this simple concept has grown to become the foundation of a simple framework, where the requests are translated into some meaningful object/objectAction/parameter1/parameter2/ combination.

Assuming that your development server is set to have .htaccess. This can be set on your apache2/conf/httpd.conf file.

Create directories and files needed

+demo
    +blue
        blue.php
    +red
        red.php
    .htaccess
    index.php
    error.php

load the .htaccess file on your source code editor e.g. notepad++, or plain text editor. Add these codes and then save.

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    #RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>

The directives above tells the apache to direct all requests to index.php. So, you don't need to do localhost/index.php?q=blue, but instead you do like this localhost/blue/.

next, load the index.php and add these codes.

function getBaseUrl()
{

    if (isset($_SERVER['HTTP_HOST'])){
            $base_url = (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off') ? 'http' : 'https';

            $base_url .= '://'. $_SERVER['HTTP_HOST'];
            $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

   }else{
            $base_url = 'http://localhost/';
        }

    return($base_url);
}

/* call the function above */
$base_url =  getBaseUrl();

/* parse the base url */
$parsed_url = parse_url($base_url);

/* take the path of the above */
$path = $parsed_url['path'];

/* isolate the purpose of this request */
$request_segments = array_filter(explode('/', (str_replace($path,'',$_SERVER['REQUEST_URI']))));

/* define your pages */

$pages = array(
            'blue' => 'blue/blue.php',
            'red' => 'red/red.php'
        );

/* set-up your statements */

if(array_key_exists($request_segments[0],$pages)){
        /* you may want to check if the file exists */
            include_once($pages[$request_segments[0]]);

}else{
        include_once('error.php');
     }

do whatever you want with red.php, blue.php and error.php

Lastly, direct your browser to

localhost/demo/blue/

If you follow my short instructions, the blue/blue.php should be loading.

Feel free to experiment with the simple function and the pages array. Actually, that is the same function found on the base_url() function of the well known framework called CodeIgniter.

Example codes provided does not deal with the parsed uri as empty or null. This can be handled easily..

I don't have the chance to test my script above, but for any reason it failed to run, please let us know. I don't visit daniweb everyday, but I do visit at least once a week.

Man Thx Alot Of Your Effort, i think you are web guru developer i ll test this right now, thx alot , have nice day lorenzoDalipio,if it possible tell me just other levels , and i ll do search aloone :), thx again