I'm working on a wo开发者_Python百科rdpress theme-switching plugin that relies on the on a php $_GET, I want to keep the URL simple and clean. Is one letter to short? Example ('t'): "foo.com/?t=theme_1"
What are the chances this conflicts with other stuff?
Of course this is somewhat subjective, and there is the obvious "p" that I should not attempt to use, but what is the best practice in this situation and in general?
There is no problem if you use one letter for $_GET. Just be sure you aren't conflicting with other lines of your code.
Most Wordpress URLs get URL-rewritten anyway.
I would say you should be ok.
There is no specific problem with using one letter vars, but because you are using wordpress, you might want to be a bit carefull: not just for that p
, but also for the future and/or other plugins
I would advise that you use something quite unique in an environment you don't have complete control over (updates etc.).
Use a prefix for you vars, maybe 2 chars + '_', or something like that.
It depends on what your priorities are. I tend to only use $_GET if I specifically want the URL to be "hackable" to allow people to either directly link to the page or to allow them to navigate around if they're paying attention. Because of this, I tend to use very clear $_GET variable names with easy to modify values, such as numbers. Ex:
"foo.com/?theme=1"
If you don't especially need either capability, there's no particular reason to use a $_GET at all - store the data somewhere else.
精彩评论