SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast jmp($fffc)'s Avatar
    Join Date
    Nov 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Concatting $_GET values to make URLs more friendly - good practice?

    If you use many variables in a URL, they tend to become unreadable. This isn't a big deal when surfing, but it starts to become a problem when you want to paste the link in an email or a forum message. I was thinking about concatting variables (the $_GET-stuff) to avoid this problem. The following URL:

    Code:
    http://www.example.com/?list=messages&sublist=inbox&sort=date&filter=unread&query=hello
    could become:

    Code:
    http://www.example.com/?v=midu&q=hello
    "m" = list is messages, "i" = sublist is inbox, "d" = sort by date, "u" = filter unread messages. The query always changes so this is a seperate variable.

    This results in a friendlier URL, and one that's bookmarkable -- which wouldn't be the case if you'd have really clean URLs by using $_POST. There are a few problems with this, though:

    • You'd have to consitently keep variables on the same place, and have them there always, even if they'd be empty. For instance, if no sort is used you'd have to use a "x" instead of "d" for date
    • It gets messy for things that use more than one character: page=23
    • It takes extra effort to properly implement this


    I was wondering what your thoughts on this are, or if there's already solutions out there that people are using.

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When it comes to readable URLs, I'm a big fan of mod rewrite.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that using such abbreviations will eventually lead to a bug in your code, unless you have seperated the internal url construction from your views (and that's probably the best way to do it).

  4. #4
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with krzyk. You'll probably find that it will get hairy somewhere along the line. (When extending the script in the future.)


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
  •