Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    $_SERVER['REQUEST_URI'] wildcard question

    Is there a way to utilize $_SERVER['REQUEST_URI'] in an IF statement so that the condition applies to all files under a specific subdir?

    so for the subdir www.foo.com/people/ -- all links under this will apply to the below conditional?

    thanks

    Code:
    if(($_SERVER['REQUEST_URI']) == '/people/'){
    
     // do something
    
    }

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post
    I would set it as a variable first

    PHP Code:
    $folder $_SERVER['REQUEST_URI'];

    if (
    $folder=='people'){
    echo(
    "yes its people")
    }
    else{
    echo(
    "no its not")

    but to answer.. yes you can... I use it to regulate meta tags by filename
    PHP Code:
    $page=$_SERVER['PHP_SELF'];
    if(
    $page==.... 

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    I don't think that does it.. let me elaborate.

    If I have the following URLs:

    www.foo.com/people/adam
    www.foo.com/people/tom/
    www.foo.com/people/sue/
    www.foo.com/people/mary/
    www.foo.com/people/joe
    ...
    and an infinite more based on various user names
    ...

    www.foo.com/people/mack
    www.foo.com/people/sally/

    how do I make an IF conditional that applies to every subdir under the parent dir "/people/"?

    something like:
    Code:
    if(($_SERVER['REQUEST_URI']) == '/people/*'){
    where * is a wildcard would be nice.. but that is obviously incorrect.

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post
    ah, i got you... now we are getting sticky... (i'm about to go to sleep, so i'll get to the reply in the a.m.) but, my mind is thinking that you will need to obtain the entire url (http://foo.com/people/sally/) then explode it by '/' (after removing the http://) and have it as:

    url[0]=www.foo.com
    url[1]=people
    url[2]=sally

    then if url[1]=='people' && url[2]!='', then do whatever

    again, its getting late and i'm running on fumes, but i think that is a start in the right direction... tell me if i'm still way off

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Generally you would use mod_rewrite to pass the page(people) and the name to a PHP page that would generate the content from there.

    Code:
    RewriteEngine On
    
    # Ignore all real files and directories.
    RewriteCond %{SCRIPT_FILENAME} -f [OR]
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteRule .* - [L]
    
    RewriteRule ^people/([^/]+)/?$	/people.php?name=$1 [QSA,L]
    This example just passes the name, which should be fine for your purposes.
    Last edited by Inigoesdr; 01-04-2008 at 06:10 AM.

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Inigoesdr View Post
    Generally you would use mod_rewrite t...
    i was definitely taking a long way around

  • #7
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know this thread is quite old but on my search for a solution to this problem I came across these solutions and none helped in my case.

    As I found an additional solution which solved my problem I hope that maybe someone else can benefit from my approach:

    Code:
    $url = $_SERVER['REQUEST_URI'];
    $subdir = substr($url,0,8);
    if ( $subdir == '/people/' ) {
    
    // whatever you want to do in this case
    
    }
    Of course you have to modify substr and the if-statement to match your situation.
    Last edited by i-am-ZZZ; 08-08-2012 at 07:11 PM. Reason: typo

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    Could also use regex:


    PHP Code:
    $ptn "@/people/*@";
    $str "/people";
    preg_match($ptn$str$matches); 
    I'm a bit of a regex noob so I wouldn't take it at face value.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •