Re: Re: create htaccess.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Adwinwijaya <adwinwijaya@xxxxxxxxxxxx>:
> Monday, December 6, 2004, 11:33:28 AM, you wrote:
>
> MWOP> In you .htaccess:
>
> MWOP>     <File index>
> MWOP>         ForceType application/x-httpd-php
> MWOP>     </File>
> MWOP>     DirectoryIndex index
>
> MWOP> Then, in your script, you'll need to access the PATH_INFO environment
> MWOP> variable via the $_SERVER array to parse out the argument(s):
>
> MWOP>     $pi   = $_SERVER['PATH_INFO']; // Grab PATH_INFO
> MWOP>     $pi   = substr($pi, 1);        // Remove the opening slash
> MWOP>     $args = split('/', $pi);       // Create array of arguments
> MWOP>     $f    = $args[0];              // Grab first argument
>
> I just want to clarify,
>
> if I type:
> www.mysite.com/article/file/19911/year/2004
> means: www.mysite.com/article.php?file=19911&year=2004 right ?
> :)
>
> and i have to put this script on my article.php, is it right ?

A couple things:

'article.php' will have to become just 'article' for the above to work
(unless you can do rewriting, but you indicated that you don't have
access to your httpd.conf file). The directions for doing that are
above; just substitute 'article' for 'index' in the <File index> area.

Second, you have to map the placement of each argument in the PATH_INFO
to a variable. So, based on the url you just provided, you'd do
something like this:

    $pi   = $_SERVER['PATH_INFO']; // Grab PATH_INFO; this will look
                                   // like /file/XXX/year/XXXX based on
                                   // your example above
    $pi   = substr($pi, 1);        // Remove the opening slash
    $args = split('/', $pi);       // Create array of arguments

    for ($i = 0; $i < count($args); $i + 2) {
        $key = $args[$i];       // Grab variable name from even-keyed
                                // arguments
        $val = $args[$i + 1];   // Grab value from odd arguments
        $$key = $val;           // Use dynamic variable assignment
    }

Basically, with PATH_INFO, YOU have to do the work of determining where
items in the url map to variables for your script.

-- 
Matthew Weier O'Phinney           | mailto:matthew@xxxxxxxxxx
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux