Forum Moderators: coopster

Message Too Old, No Replies

request_uri

Can I use a wildcard?

         

madmatt69

4:39 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone,

trying to make a small function that will determine what directory the file is in, and based on that, display a specific link.

I'm trying to use the request_uri command but I can only put in an exact directory..it doesn't work if you're in a sub-directory of that initial directory. I'll try to explain a little better :)

Here's the code I have now:
---
$url = $_SERVER['REQUEST_URI'];

if($url == '/red-widgets/'){
---

But I want it to work if say someone goes to /red-widgets/small/smallredwidgets.php

Know what I mean? Sorry I'm not the best at explaining this.

Any help would be much appreciated!

jollymcfats

4:58 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



You just need to extract the first component out of the REQUEST_URI. Here's one way to do that:


$dir = substr($_SERVER['REQUEST_URI'], 1, strpos($_SERVER['REQUEST_URI'], '/', 1) - 1);

if ($dir == 'red-widgets') { ... }

coopster

5:47 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may also want to check into using $_SERVER['PHP_SELF'] [php.net] and/or pathinfo() [php.net]. explode() [php.net] would be another option to separate the directories, too.

madmatt69

6:30 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Worked perfect :) Thanks!