URL use "/" instead of "?" to send variables

Discussion in 'PHP' started by rahulephp, Jun 21, 2010.

  1. #1
    Hi,
    In normal php, We use ?id=123 to send variable through URL.

    So, the URL would be www.example.com/page.php?id=123 and then we use $_REQUEST['id'] to receive the variable on another page.

    But my question is, if I use "/" instead of "?" (Ex: www.example.com/page.php/id/123), then how to receive the "id" on page.php.

    $_REQUEST['id'] doesn't works in this case.

    Thank you in advance
     
    rahulephp, Jun 21, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    You do it via mod_rewrite

    a rule similar to this one would be used.

    
    RewriteCond ^page.php/(a-z*)/(0-9*)$ page.php?$1=$2
    
    Code (markup):
     
    stephan2307, Jun 21, 2010 IP
  3. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow, this is exactly i was looking for.
    Thanks in bunch stephan
     
    rahulephp, Jun 21, 2010 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    Also you can parse $_SERVER['REQUEST_URI'] for more complex url setup without complex and long mod_rewrite
     
    AsHinE, Jun 21, 2010 IP
  5. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i'll definitely use. Thanks
     
    rahulephp, Jun 21, 2010 IP