(free) short url script exactly like used on iceurl.com?

Discussion in 'PHP' started by Choller, Jun 16, 2007.

  1. #1
    I've been browsing google all day but I couldn't find a (free) script to create something exactly like IceURl.

    the requirements:
    1. make a random generated text
    2. don't use any special characters like "?"

    url needs to be something like this --> www.mysite.com/XOoso2

    Can anyone name any?
     
    Choller, Jun 16, 2007 IP
  2. mojojuju

    mojojuju Peon

    Messages:
    53
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Take a look at Get Shorty. It might be what you're after.
     
    mojojuju, Jun 16, 2007 IP
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    creating a random string of 5 characters

    
    <?php
        $chars = "abcdefghijklmnopqrstuvwxyz1234567890";
        $key = "";
    
        for($x = 0; $x <= 4; $x++)
        {
            $key .= $chars[mt_rand(0,strlen($chars)-1)] ;
        }    
    ?>
    
    PHP:
    it's up to you from there.
     
    ansi, Jun 16, 2007 IP
  4. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ansi, this is just a question, but does that give any better performance (or randomness) than just using str_shuffle?

    I used to loop it and select random characters, but I figure this'd be quicker

    
    $chars = "abcdefghijklmnopqrstuvwxyz1234567890";
    $result = substr(str_shuffle($chars), 0, 10);
    
    PHP:
     
    decepti0n, Jun 16, 2007 IP
    ansi likes this.
  5. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #5
    not that i would think, just how i would do it.
     
    ansi, Jun 16, 2007 IP
  6. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks guys, especially mojojuju because i'm going to use that script.
     
    Choller, Jun 17, 2007 IP
  7. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Or you could use a hash function like md5(), it's even shorter.
     
    MartiCode, Jun 17, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    ^^ But it would get the same ID if 2 persons want to mask the same URL. Plus it would return a 32 characters value, which is probably longer than the original URL at the end...
     
    nico_swd, Jun 17, 2007 IP
  9. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That might be a desired feature - it makes sense that the same target URL has the same short-URL (unless there's some specific requirement that it's different)

    You could cut the hash to the desired length. The chance of it being unique is obviously reduced but I'm guessing it's no more than with a random string of the same length.
     
    MartiCode, Jun 17, 2007 IP