Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Generating URL

  1. #1
    Join Date
    Jan 2010
    Posts
    3,641
    Tokens
    138

    Latest Awards:

    Default Generating URL

    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

  2. #2
    Join Date
    May 2005
    Location
    /etc/passwd
    Posts
    19,110
    Tokens
    1,139

    Latest Awards:

    Default

    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.
    Quote Originally Posted by Chippiewill View Post
    e-rebel forum moderator
    :8

  3. #3
    Join Date
    Jan 2010
    Posts
    3,641
    Tokens
    138

    Latest Awards:

    Default

    Quote Originally Posted by Recursion View Post
    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?

  4. #4
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    846
    Tokens
    1,766
    Habbo
    triston220

    Latest Awards:

    Default

    Use
    PHP Code:
    Rand() 
    to generate a random number.


    Quote Originally Posted by Jaaaack! View Post
    See, however much I want this, my girlfriend uses my PC too much, and I would be killed.





  5. #5
    Join Date
    Jan 2010
    Posts
    3,641
    Tokens
    138

    Latest Awards:

    Default

    Quote Originally Posted by triston220 View Post
    Use
    PHP Code:
    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?

  6. #6
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    846
    Tokens
    1,766
    Habbo
    triston220

    Latest Awards:

    Default

    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.


    Quote Originally Posted by Jaaaack! View Post
    See, however much I want this, my girlfriend uses my PC too much, and I would be killed.





  7. #7
    Join Date
    Jan 2011
    Location
    England, United Kingdom
    Posts
    253
    Tokens
    40
    Habbo
    Pegle

    Latest Awards:

    Default

    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.


  8. #8
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    846
    Tokens
    1,766
    Habbo
    triston220

    Latest Awards:

    Default

    Quote Originally Posted by .Owen!: View Post
    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?

    PHP Code:
    $imageid Strip_tags(mysql_real_escape_String($_GET['imageid'])) //Remove anything stupid.
    $imageid = (int)$imageid //Cast type to integer. 


    Quote Originally Posted by Jaaaack! View Post
    See, however much I want this, my girlfriend uses my PC too much, and I would be killed.





  9. #9
    Join Date
    Jan 2011
    Location
    England, United Kingdom
    Posts
    253
    Tokens
    40
    Habbo
    Pegle

    Latest Awards:

    Default

    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.


  10. #10
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    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]
    Chippiewill.


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •