开发者

php create beautiful query string from long query string

i want to create a beautiful query string from long and easily understandable query string

for example

http://www.domain.com/play.php?a=10&b=20&c=30

first of all this is vary long query string and second it is understand able that value of a,b&c.

what i want is php function which convert whole query string to a=10&开发者_运维知识库amp;b=20&c=30 to some text like f4cdret4

and then i pass same like

http://www.domain.com/play.php?q=f4cdret4

and in play.php i again convert back f4cdret4 to a=10&b=20&c=30

i am trying to find some thing like that but many days searching no success.

Thanks


This is a BAD idea from a usability perspective. I as a user would be annoyed with you. I recommend you read about URL Design.

Also, sounds like you want to keep something from the user. If so it's not secure if you do something like

$url .= '?q=' . base64_encode(http_build_query($parms));


You could use some string transformation functions to hide the real query string. Here is a simple example I came up with using bin2hex and pack

<?php
$str = 'a=10&b=5&c=20&d=6';
$encoded = bin2hex($str);
echo $encoded;
echo "\n";
echo pack("H*",$encoded);
?>

example You can use bin2hex to encode it, and pack to decode it.


Generally speaking, you don't want to divorce your URL from any semblance of meaning for the user unless you are significantly shortening it for use in character-limited settings like a Twitter post.

That said, there are a few ways to implement this. You can:

  • Pre-generate these URLs and store the cross-referenced query string in the database (use "f4cdret4" as a unique index, "a=10&b=20&c=30" as a second column)
  • Mash them together with some kind of separator (a=10&b=20&c=30 becomes "a10-b20-c30")
  • Use htaccess to make pseudo-directories (a=10&b=20&c=30 becomes "mydomain.com/q/10/20/30")

    RewriteEngine On

    RewriteRule /q/(.*)/(.*)/(.*)$ /page/play.php?a=$1&b=$2&c=$3

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜