how to show links as md5 instead of normal link
I have a bunch of links in my database and I use $row['url'] to display them but what I would like to do is instead of show the url have it show something like http://mywebsite.com/3e8aa15443dcce0b886af4616a1c1645 I have the md5 for every link available in the database and can display md5 using $row['md5'] but how can I make the urls show like something I posted above and still g开发者_开发百科o to the correct link when clicked? Can anyone help me?
You want to make a new column (or table however you like) that stores the md5sum for the given URL. You'll enter this md5sum at the same time you are entering in the url data.
Then you'll have a RewriteRule ([a-z0-9]+) lookup.php?md5=$1
in your .htacess file.
Then in lookup.php you'll create a query that uses the passed in md5sum sum. something like select url from sometable where md5 = '$escapedMD5' limit 1
. Just be sure to escape the md5sum that is being passed in on the url with your db's appropriate escape function (mysql_real_escape_string etc).
After getting back the url from the result you'll do have a final line of code in lookup.php that does a header( 'Location: ' . $urlFromDB ) ;
This is the general idea at least, hopefully you can take it from here.
You could precompute the md5s of each link and store it in a DB. When you get a request for a url, make a lookup against your precomputed hashes and redirect them.
IF the MD5 values are unique, then you can create a page that given the MD5 return the corresponding page. Do you use any of PHP framework?
You can you apache mod rewrite rule to achieve the mapping
I would suggest using a rule like this
http://example.com/link/etghfcvfdfgfgjjijhgyhgc.php
To capture the above link you can use this rewrite rule
RewriteRule ^/link/(.*).php /link.php?linkHash=$1
I have not checked the above rule but giving you an idea
Please refer apache mod_rewrite documentation.
精彩评论