View Full Version : Generating URL
Thomas
20-11-2011, 09:00 AM
I am making a image uploading website and i have got it to upload the image to a mySQL database and display the image however i am not sure how i can generate a a random URL ending which links to the image they uploaded.
Not very well explained but i'm sure you know what i mean.
e.g www.domain.com/w7djw38d
Recursion
20-11-2011, 11:06 AM
I guess you'd have to write a PHP script to pull the image and use an htaccess rewrite rule to make the URL. Sorry I can't be of more help though.
Thomas
20-11-2011, 11:09 AM
I guess you'd have to write a PHP script to pull the image and use an htaccess rewrite rule to make the URL. Sorry I can't be of more help though.
Ok, anyone want to explain how htaccess works?
triston220
20-11-2011, 11:34 AM
Use
Rand() to generate a random number.
Thomas
20-11-2011, 11:57 AM
Use
Rand() to generate a random number.
So I could you 'Rand()' to do:
'www.domain.com/21891' ??
if yes, how do I assign that to the users image?
triston220
20-11-2011, 12:49 PM
You could check a GET argument (E.G. imageid) to get the relevent image.
Example:
Yoursite.com?imageid=3569346
If I rember correctly, Rand() takes two argunents. These are Lower Bound and Upper Bound.
Pegle
20-11-2011, 06:57 PM
Using a GET would be a security risk. Umm phpacademy has a similar tutorial but with a url shortener you could use the generating bit from that tutorial for it.
triston220
20-11-2011, 07:59 PM
Using a GET would be a security risk. Umm phpacademy has a similar tutorial but with a url shortener you could use the generating bit from that tutorial for it.
How would it?
$imageid = Strip_tags(mysql_real_escape_String($_GET['imageid'])) //Remove anything stupid.
$imageid = (int)$imageid //Cast type to integer.
Pegle
20-11-2011, 08:05 PM
I wouldn't say it's a security risk, but yeah. Don't judge just when I was making something someone told me about using GET and random numbers in URL's was dangerous but I can't remember. So try it it's not that bad.
Chippiewill
20-11-2011, 09:14 PM
Ok so I'm assuming you store the images on the sql like: IMAGE ID | IMAGE FILE (And then maybe some meta data)
So first you need to make the image displayed be called by:
image.php?id=3453245345
Just have the number auto-increment, you'll avoid problems down the line. Then in order to format it to domain.com/3453245345 you need to use mod_rewrite.
You probably need something like this:
RewriteEngine On
RewriteRule ^/([0-9]{4})$ /image.php?id=$1 [L]
triston220
23-11-2011, 09:36 PM
I wouldn't say it's a security risk, but yeah. Don't judge just when I was making something someone told me about using GET and random numbers in URL's was dangerous but I can't remember. So try it it's not that bad.
Possibly that somebody was referring to the risks of SQL injection. Unless you've sanitised your input (Like in my example above) you are at risk of having your database / security checks compromised. I wasn't judging. :) Strictly speaking, when you just need a number, you only really need to cast type.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.