Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

O'Reilly:
Downloading Uniquely
Dec 06, 2002 @ 13:55:35

So, your website is up and perfect, and search engines can get to just about everything thanks to some cool Apache rewrite rules and some fancy coding on your part. So now, what happens if you want to provide a one-time URL to a viewer. If you have some product or software that you're selling, you really don't want to give that customer a permalink directly to the software itself. Your hard work would be wasted as the link got passed around - not a pretty scenario.

Well, the O'Reilly Network just might have something that will help you out. Their latest article, Generating One-Time URLs with PHP, talks about just that - using the md5() and uniqid() functions to allow you to create an ID you can safely give the user. The "token" is stored in a temp file, and then checked later. If it's in the temp file, then the readfile() command is used to output the file directly to the user's browser. Voila! A simple, quick system that'll let you keep your application safely hidden behind a unique ID.

It's a pretty good idea to do something like this on your site, especially if you're really trying to make it easy on your customers. All they have to do is click that link, and away they go. And, since the md5() function uses the rand() function anyway, you have a pretty good assurance that you are generating a good, unique ID number.

tagged:

Link:


Trending Topics: