Results 1 to 2 of 2

Thread: Execute code based upon URL

  1. #1
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Execute code based upon URL

    Hi there,

    I would like to be able to execute a piece of code using PHP, based upon part of the URL. For example:

    Code:
    IF CurrentURL CONTAINS "/contact/" OR "/contact.php" THEN
       DISPLAY HTML code
    ELSE
       DISPLAY HTML code
    How would I go about inspecting the current location to see if it includes a particular path or file?

    Thanks heaps,
    Stuart.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The URL after the current file is contained in $_SERVER['PATH_INFO']. E.G.:
    Code:
    if(starts_with($_SERVER['PATH_INFO'], '/user/register'))
      if(@$_POST['action'] === 'register')
        User::register_handler($_POST);
      else
        exit(User::register_form());
    The user could then go to /path/to/your/script.php/user/register and get the register page. Removing that annoying '.php' from the URL is simply a case of forcing the handler:
    Code:
    <FilesMatch "^yourscript$">
      ForceType application/x-httpd-php
    </FilesMatch>
    ... and removing the .php extension from the bootstrap file.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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