SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clean URL with $_SERVER['PATH_INFO'] (Merged)

    Hi,
    I am trying to clean URL with $_SERVER['PATH_INFO'], why nothing comes out when I test it on my localhost?

    Code:
    $data = explode('/',$_SERVER['PATH_INFO']);
    print_r ($data);
    result:
    Array ( [0] => )

    but when i test it with $_SERVER['REQUEST_URI'], then it has some result...

    Code:
    $data = explode('/',$_SERVER['REQUEST_URI']);
    print_r ($data);
    result:
    Array ( [0] => [1] => folder [2] => file.php?pg=home )

    Is it something to do with the configuration in my apache?

    Please let me know if u have any idea. Many thanks.

    Lau

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats the PHP version you using, try printing out all the Server variables and see whats available

    Code:
    print_r($_SERVER);

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lphy View Post
    whats the PHP version you using, try printing out all the Server variables and see whats available

    Code:
    print_r($_SERVER);
    Thanks for the reply. i wont use $_SERVER['PATH_INFO'] then.

    Does any one know what the idea behind using $_SERVER[] to clean the URL?

    I have read a few tips online but I still cant get my head around it,

    These are the source I came across so far, does any one know of a better source or tutorial about cleaning the URL without actually has to worry about mod_rewrite?

    http://www.tutorio.com/tutorial/php-alt ... endly-urls
    http://www.dobre.name/tutoriale/php/cle ... write.html
    http://agachi.name/weblog/archives/2005 ... y-urls.htm

    Many thanks,
    Lau

  4. #4
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clean URL with $_SERVER without mod_rewrite?

    Hi,

    I have posted a thread before about cleaning URL with $_SERVER['PATH_INFO'], and knowing it is not a good one to clean URL. Which indices of $_SERVER is the best for cleaning URL then?

    After all, does any one know what the idea behind using $_SERVER to clean the URL? I still cant get it yet after reading a few tips online...

    These are the source I came across so far, does any one know of a better source or tutorial about cleaning the URL without actually has to worry about mod_rewrite?

    http://www.tutorio.com/tutorial/php-alt ... endly-urls
    http://www.dobre.name/tutoriale/php/cle ... write.html
    http://agachi.name/weblog/archives/2005 ... y-urls.htm

    Many thanks,
    Lau

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,184
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    1.) first item is the controller
    2.) everything that follows are options

    There is a table for controllers in my database.

    controllers
    -- id
    -- name (url)
    -- location (file path)

    Thus, if someone where to go to /index.php/home that would locate the record where the name is equal to home.

    The I have another table

    controller_options
    -- id
    -- controller_id (associated controller)
    -- placement
    -- name
    -- required

    The options for the controller are expressed in that table. So if someone where to go to /index.php/gallery/1 that would enact the gallery controller and find the related options. In this case the 1 following the controller would be displaced as the name for that controller option for the associated controller. So that name could be id.

    Then I use a php class to manage this which replaces $_GET.

    $id = $path->hasOption('id')?$path->getOption('id'):0;

    This makes it possible to drop any options that shouldn't be there. Actually they are dropped. If you where to go to /index.php/gallery/1/2 and a second option didn't exist it would be dropped. So upon calling $pathway->makeUrl() the 2 wouldn't exist. That call would return /index.php/1 regardless of how many indexes someone attempted to input - /index.php/1/2/56/rtttt/hj

    Seems to be working well so far.

    I then also have separate tables for models and views. A controller to (models,views) is a many to many relationship expressed through a look-up table. So upon finding the controller all the associated models and views are also brought in which eliminates the need for weird string/naming conventions.

    There is also one entry point for the application which is a constant that resides inside the Pathway class. So to build any url would use Pathway::entry. That would be equal to /index.php in this case. However, its simple to change. Just change the constant a different entry point for the app can be used.

    The only problem is that a controller can't bring in another controller dynamically. So something like this isn't possible: /index.php/admin/blogs. In that case the admin controller would be brought in not the blogs controller. So it would be better expressed like the following in the way i have my system set up /index.php/admin-blogs/.

  6. #6
    SitePoint Addict CWebguy's Avatar
    Join Date
    Mar 2009
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Clean URLs without mod_rewrite,

    I didn't know there was such a thing.

    I always set a baseurl variable in my configuration for doing URLs, I never mess with the server variables.

    Cheers,


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
  •