Re: Low-Cost PHP Hosts?

From: Date: Fri, 10 Nov 2000 11:13:12 +0000
Subject: Re: Low-Cost PHP Hosts?
Groups: php.general 
Request: Send a blank email to php-general+get-24643@lists.php.net to get a copy of this message
Addressed to: Distribution list (see below) ** Reply to note from "David P. Schwartz" <davids@desertigloo.com> Thu, 09 Nov 2000 13:16:50 -0700 Try this: Edit your httpd configuration, in the <VirtualHost> block for the site in question add: <LOCATION /my_program> ForceType application/x-httpd-php </LOCATION> Use "ForceType application/x-httpd-php3" for php3. Restart the web server so new the config takes effect. You may be able to use .htaccess for this, but I don't use them so I don't know. Now create a php program called my_program in the DocumentRoot of the domain. Note there is NO file extension on this file name! my_program ------------------------------------------------ <? list( , $Variable1, $Variable2, Variable3 ) = explode( '/', $PATH_INFO ); echo "Variable1: $Variable1<BR>\n", "Variable2: $Variable2<BR>\n", "Variable3: $Variable3<BR>\n"; ?> ------------------------------------------------ Now hit the page: http://www.yourdomain.tld/my_program/these/are/variables/index.html and see what you get. I will leave it as an excercise for the reader to obtain and use the 'index.html' part of the URL. See: http://www.php.net/manual/ref.array.php for other cool things you can do with the output of the explode. It is just an array... I usually end up using array_shift() and array_pop() to remove the first and last elements which control what the program will do, then implode() what is left back into a path determining what is acted upon. For example: http://www.mvas.net/events/2000/11/11/ShowDay.php events is the name of the php program that manages my events calendar. ShowDay.php is array_pop()'ed off the end to determine what to do, and 2000, 11 and 11 are combined to create the day to act on. http://www.mvas.net/events/index.php and http://www.mvas.net/events/2000/12/welcome.php are also valid URLs this program can handle, which show why you might want to array_pop() the last item, and interpret it as a command before you implode() the rest of the data back into a date. > Innovative, but awfully verbose! Try something like this, that I use if > stuff expected to be on the querystring is missing: > > > if (!empty($PATH_INFO) and ($PATH_INFO[0] == "/")) > > { > > $pi = substr( $PATH_INFO, 1, 999 ); > > $data_ary = split( "=", $pi ); // we get > > /{$data_ary[0]}={$data_ary[1]}/... > > $form[$data_ary[0]] = $data_ary[1]; > > } > > > > -David Schwartz > > Brian Clark wrote: > > > Nebbe, Joelle wrote: > > > > >>and to search engines. > > > > > >Alas no, it will only work as long as you do not pass parameters > > >If you start passing parameters many search engines will decide to > > >ignore it (characters like ?, &, =) > > >unless you configure your system to allow things like > > > > > > > >>http://myserver/some/path/here/index.html/variable1/variable2 > > > > > >Now i have done this with cgi scripts, using scriptalias, but I > > >have not tried it with php. Not sure how you can do it without > > >having too much of a performance hit for every other page. > > > > While not pretty, I use something along the lines of: > > > > function ParseQueryString() > > { > > /* Ie: script.php/var1=value/var2=value */ > > > > $request = $GLOBALS['REQUEST_URI']; > > ereg("/([[:alnum:]]+\.php3?)", $request, $match); > > if(count($match) > 0) > > { > > $string = explode("$match[1]/", $request); > > $query = explode("/", $string[1]); > > while(list(,$value) = each($query)) > > { > > $pair = explode('=', $value); > > $GLOBALS[$pair[0]] = $pair[1]; > > } > > } > > } > > > > But I'm sure there is an easier way. > > > > -Brian Rick Widmer Internet Marketing Specialists www.developersdesk.com Distribution list: "David P. Schwartz" <davids@desertigloo.com> php-general@lists.php.net Brian Clark <brianj@fusionwerks.com> "Nebbe, Joelle" <Joelle.Nebbe@rim.co.uk>

« previous php.general (#24643) next »