I'm making a gallery website. Photos and albums should be hidden from the public by default, but the owner can share a public URL if he wants. I also want to use short URLs for this.
I'm trying to figure out the best way to do this. At first I thought I could have a MySQL table with the short URL code (something like Zneg8rjK
), and the full URL (/album/5/
). When the user visits this link (mysite.com/Zneg8rjK
) it would set a session variable which is just a hash of /album/5
plus a salt, and then it redirects them to the full URL. Then on that page I can just rehash the current page and check if it's in their session or not. No problem... but what happens when they click on a photo in that album? It breaks down.
So, the next solution I thought of was that I should store a secret key with each album and each photo, and then have a public address like /album/5/secretkey
. The short URL could just point to this instead. But then how do I give the user to permission to view all the photos in the album? Should I just link each photo to point to the secret version of the photo URL instead, but only if they accessed the album via the secret album URL? My concern is that I want to keep the secret keys/URLs out of the address bar as much as possible so that users don't accidentally share it with people they shouldn't... but it's not a huge concern if there aren't any better solutions.
Thoughts?
Wait a sec, do I even need to hash the URL? There's no way for clients to modify session variables is there?