Re: Variable Passing
| From: | Matthew Weier O'Phinney | Date: | Sat, 09 Apr 2005 18:56:26 +0000 |
| Subject: | Re: Variable Passing | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-212739@lists.php.net to get a copy of this message | ||
* Brad Brevet <bradbrevet@ropeofsilicon.com>:
> This seems to be what I was looking for, but I am curious, will the "/" be
> included in the variable? Will I have to do a stripslashes() command on it?
If you echo out $_SERVER['PATH_INFO'] for the URL shown below, it will
give you:
/321
Usually what you do is something like:
$pi = substr($_SERVER['PATH_INFO', 1);
$args = explode('/', $pi);
and then you'll have an array of arguments without the forward slashes.
If you're only expecting a single argument, you can possibly skip that
second step; if you want to limit the number of arguments you'll accept,
you can add a third parameter to the explode() function call.
You should still treat data passed in this way as tainted, just like
data from the query string or a form. Scrub it and validate it before
doing anything with it.
Note: to get a script called 'something' to be parsed as PHP on your
server, you'll need to do the following (assuming you're using Apache):
create a .htaccess file in that directory with the contents:
<Files ~ "(something)$">
ForceType application/x-httpd-php
</Files>
This will tell Apache that the file is a PHP script.
> "Hans Juergen von Lengerke" <lengerkeh@sixt.de> wrote in message
> news:Pine.LNX.4.58.0504081630480.6751@windsor.sixt.de...
> > > Brad Brevet:
> > >
> > > Hi, I am curious how to pass a variable without using something like
> > > id=321.
> > >
> > > I have seen sites that have something like
> > > http://www.website.com/something/321 and the variable
> > > is passed
> > > how exactly is that done? And is it called something specific so I
> > > know how to refer to it in the future?
> >
> > You can do that with $_SERVER["PATH_INFO"]. If your script
> > is /something, this variable will be set to /321
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org