
|
View Full Version : php3-parameter with / instead of ?
Martin 06-29-2001, 09:54 AM I'm not sure if this is the right place to ask that but I will try it.
I want to append php3-parameters with an '/' instead of the usual '?' . It should look like:
http://www.myhost.com/index.php3/parameter1/parameter2/
How can I do that?
Chicken 06-29-2001, 11:05 AM Originally posted by Martin
I want to append php3-parameters with an '/' instead of the usual '/' .
Is this a trick question? :confused:
Martin 06-29-2001, 11:17 AM I'm very sorry, I corrected it. I meant / instead of ?.
Martin
Originally posted by Chicken
Is this a trick question? :confused:
WildWayz 06-29-2001, 11:47 AM aaah I know what u mean - I have seen it on pages before.
Not sure how to do it tho - maybe a regexp ?
--James
drhonk 06-29-2001, 12:18 PM There is a way to do it .. using template and also use rewrite option on your apache.
So when you open one of your php script you can have it like www.yourdomain.com/script/parameter/parameter
ezPublish, a content management script, is using this kind of method. Go to their website publish.ez.no and read on their installation documentation, maybe even download their script and try it out. That way you can also learn how they got it to work.
alpha 06-29-2001, 12:35 PM never tried this myself but here's an idea...
try exploding
$PHP_SELF
or
$REQUEST_URI
or even
$SERVER_NAME.$REQUEST_URI
$SERVER_NAME.$REQUEST_URI will give you the following string:
www.yourdomain.com/script/script.php
if you request that variable here:
http://www.yourdomain.com/script/script.php/this/work
then you'll get this string stored in that variable:
www.yourdomain.com/script/script.php/this/work
now, what you have to figure out now is to either explode it or use regular expressions to match a pattern to it...
i dunno if this is the best way, but it certainly would work ;)
if you have a static number of variables you want to pass and just a couple variables... easiest way to do it will be just explode it and use the array[num]... but if the number of variables will vary or you have ALOT of variables to pass, then regular expressions is the way to go :)
g'luck
Martin 06-29-2001, 02:57 PM Originally posted by drhonk
There is a way to do it .. using template and also use rewrite option on your apache.
So when you open one of your php script you can have it like www.yourdomain.com/script/parameter/parameter
ezPublish, a content management script, is using this kind of method. Go to their website publish.ez.no and read on their installation documentation, maybe even download their script and try it out. That way you can also learn how they got it to work.
Thank you for that idea, they are working with mod_rewrite. That was a technology I wanted to use first. But either I don't find the right RewriteRule or something with the rewriting is wrong on the site of my provider. I always get just a 404-page. But I think the rule should be correct. I looks like that at the moment.
'RewriteRule ^(.*)/(.*)/(.*)$ /index.php3?parameter1=$1¶meter2=$2 [L,R]'
In an older version I used ([A-Za-z0-9_]+) instead of (.*). With the same result.
Martin
Martin 06-29-2001, 03:01 PM Originally posted by alpha
never tried this myself but here's an idea...
try exploding
$PHP_SELF
or
$REQUEST_URI
or even
$SERVER_NAME.$REQUEST_URI
$SERVER_NAME.$REQUEST_URI will give you the following string:
www.yourdomain.com/script/script.php
if you request that variable here:
http://www.yourdomain.com/script/script.php/this/work
then you'll get this string stored in that variable:
www.yourdomain.com/script/script.php/this/work
now, what you have to figure out now is to either explode it or use regular expressions to match a pattern to it...
i dunno if this is the best way, but it certainly would work ;)
if you have a static number of variables you want to pass and just a couple variables... easiest way to do it will be just explode it and use the array[num]... but if the number of variables will vary or you have ALOT of variables to pass, then regular expressions is the way to go :)
g'luck
Thanks for that tip. I tried it already with REQUEST_URI and PATH_INFO. The problem is, as soon as I call the page like that:
http://www.mydomain.com/index.php3/parameter
(so if I substitute the ? by an / ) , I get an runtime error and the browser stops execution and I get a screwed up page. I don't know what's wrong.
STheroux 06-29-2001, 03:03 PM I actually do this on one of my sites <www.classicreader.com (http://www.classicreader.com/)> to keep the url's search-engine friendly. The "parameters" will be available in PATH_INFO.
Example:
url: http://www.classicreader.com/toc.php/sid.1/bookid.1248/
PATH_INFO will contain the string "/sid.1/bookid.1248/"
I then drop the leading and trailing "/" and split the parameters on the remaining "/".
$params = explode("/", $vals);
In my case, I also further split the parameters on "." so the example url above is equivalent to:
http://www.classicreader.com/toc.php?sid=1&bookid=1248
Stephane
Martin 06-29-2001, 03:18 PM Originally posted by STheroux
I actually do this on one of my sites <www.classicreader.com (http://www.classicreader.com/)> to keep the url's search-engine friendly. The "parameters" will be available in PATH_INFO.
Example:
url: http://www.classicreader.com/toc.php/sid.1/bookid.1248/
PATH_INFO will contain the string "/sid.1/bookid.1248/"
I then drop the leading and trailing "/" and split the parameters on the remaining "/".
$params = explode("/", $vals);
In my case, I also further split the parameters on "." so the example url above is equivalent to:
http://www.classicreader.com/toc.php?sid=1&bookid=1248
Stephane
That's what I tried already. But like I described in the comment above, as soon as I call the script with a following slash, I get an runtime error. No clue why.
Martin
alpha 06-29-2001, 03:23 PM Originally posted by Martin
Thanks for that tip. I tried it already with REQUEST_URI and PATH_INFO. The problem is, as soon as I call the page like that:
http://www.mydomain.com/index.php3/parameter
(so if I substitute the ? by an / ) , I get an runtime error and the browser stops execution and I get a screwed up page. I don't know what's wrong.
hmm, i guess you didn't understand what i was trying to tell ya... the idea i posted earlier didn't specifically do what you wanted... it does not allow the following:
http://www.yourdomain.com/script.php/var=blah/
to be changed into the following...
http://www.yourdomain.com/script.php?var=blah
-------------BUT------------
what i was trying to tell you was that you can use the http vars to retrieve the current URL... what you needed to do is basically code a little function that will take all the parameters out of the 'slashed' URLs which isn't very hard to do
g'luck
alpha 06-29-2001, 03:26 PM Originally posted by Martin
That's what I tried already. But like I described in the comment above, as soon as I call the script with a following slash, I get an runtime error. No clue why.
Martin
hmmm... i don't see why there could be a runtime error if you did everything correctly... maybe post the code in here?
STheroux 06-29-2001, 03:41 PM Here's the code I use (with added comments):
// get rid of leading slash
$vals = ereg_replace("^/", "", $PATH_INFO);
// get rid of trailing slash
$vals = ereg_replace("/$", "", $vals);
// split on the remaining slashes
$params = explode("/", $vals);
// At this point, all of the parameters are in the array $params
// I now split the parameters on the "." and get the parameters I need
// You could also use "=" as the delimiter (i.e. /param1=foo/param2=foo/)
while (list ($key, $val) = each ($params)) {
$param = explode(".", $val);
if ($param[0] == "bookid") {
$bookid = $param[1];
}
elseif ($param[0] == "sid") {
$sid = $param[1];
}
elseif ($param[0] == "sec") {
$sec = $param[1];
}
elseif ($param[0] == "plain") {
$plain = $param[1];
}
}
With the url "www.classicreader.com/read.php/sid.1/bookid.1248/sec.2/plain.1/", I end up with:
$sid = 1;
$bookid = 1248;
$sec = 2;
$plain = 1;
Stephane
Martin 06-29-2001, 04:25 PM Originally posted by STheroux
Here's the code I use (with added comments):
Stephane
Thanks, I mailed you my code, maybe you can find an error somewhere.
But I assume the server doesn't see the index.php3 as a script-file but just as an directory. I think so because when I call it with 'index.php3/home' then the REQUEST_URI is only 'home' . So it doesn't see the script. What is wrong? Do I need a ForceType-Directive on the server?
Martin
|