开发者

Alternative syntax to GET in url

I've inherited terrible code in the past, but one idea in there struck me as a logical step. It's to use non-standard get queries for links inside the application.

So instead of

/search?category=23&city=Venice

when applicable, use

/search/category-23;city-Venice

These kind of uris get parsed for comfortable use by the system and any $_GET params can still come at the end of the uri.

The main advantage is that no outside link with say referrer information, or (much more importantly) requests from other services like banks will by chance override information in the specially formated qu开发者_运维知识库ery.

I realize the many downsides of this approach and as mentioned this notation is only used where appropriate.

The question is, are there any best practices in doing such a thing, as I'm reimplementig this particular functionality and would rather use a premade solution (the key-value; format does not have to stay).

P.S. I can't believe [best-practices] is no longer a tag :/

EDIT: I might have been misunderstood. I still use GET, I just want some extra information embedded in the URL that can't accidentally be overriden by outside requests or whatnot.

I do need this functionality I'm just asking are there any practices. For example I found out yesterday, skype (and I suppose other services too) strip the leading ;, when auto-linkifying, so it's better to use, say | as the separator.


Just use regular a GET request. If you don't, then not only do you have to write and debug new parsing code, but you're also side-stepping a lot of form functionality provided by browsers, web servers, web crawlers, client-side scripts, and server-side frameworks.

However, if you're just trying to make your URLs nicer, then use mod_rewrite or one of its cousins to do something like this:

/search/23/Venice?q=road+map -> /search?category=23&city=Venice&q=road+map
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜