Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 662495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:23:05+00:00 2026-05-13T23:23:05+00:00

I’m creating a link shortening service and I’m using base64 encoding/decoding of an incremented

  • 0

I’m creating a link shortening service and I’m using base64 encoding/decoding of an incremented ID field to create my urls. A url with the ID “6” would be: http://mysite.com/Ng==

I need to also allow users to create a custom url name, like http://mysite.com/music

Here’s my (possibly faulty) approach so far. Help in fixing it would be appreciated.

When someone creates a new link:

  • I get the largest link ID from the database (it’s not auto incremented)
  • Increment the ID by 1
  • Generate a short URL code (http://website.com/%5Bshort url name]) by base64_encoding that ID
  • Insert into links table: id, short_url_code, destination_url

When someone creates a new link and passes a custom short URL:

  • My plan was base64_decode their custom string and use that as the link ID, but I didn’t realize that you can’t just base64_decode any alphanumeric string and turn it into a number.

Is there a better encoding method that will let me turn any number into a short string, and any string into a number, so I can always lookup short urls (whether custom or autogenerated) by turning the name into a number and querying for a link with an ID equal to that number?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:23:05+00:00Added an answer on May 13, 2026 at 11:23 pm

    First and foremost, make sure you have unicity constraints in place on the ID and short_url_code columns.

    When someone creates a new link:

    1. Get the next largest link ID from the database (for performance reasons you should really REALLY use autoincrement or SEQUENCE, depending on what your RDBMS offers; otherwise go ahead and select MAX(ID)+1 )
    2. Generate a short URL code (http://website.com/[short url name]) from ID using base64_encode or any other custom or standard encoding scheme
    3. Insert into the links table: ID, short_url_code, destination_url
    4. If the insert fails because of a constraint violation go back to step 1 to try a new ID; you may have had a violation because:

      1. the same ID has already been used (i.e. inserted) in parallel by another thread/process etc. (this will not happen if you used autoincrement or SEQUENCE, and may happen quite often otherwise), and/or
      2. the same short_url_code has already been used as a custom URL (this will happen very seldomly unless someone is trying to cause trouble on your site)
    5. If the insert succeeded, commit and return the short URL to the user

    When someone creates a new link and passes a custom short URL:

    1. Perform the same step 1 as above
    2. Instead of generating the short URL part from ID as in step 2 above, use the custom short_url_code provided by the user
    3. Perform the same step 3 as above
    4. If the insert failed because of:
      1. a constraint violation on ID: go back to step 1 to try a new ID
      2. a constraint violation on short_url_code: return an error to the user asking him to pick a different custom URL, as the short URL he/she provided has already been used
    5. Perform the same step 5 as above
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no such function, since you'll need private symbols… May 16, 2026 at 2:21 pm
  • Editorial Team
    Editorial Team added an answer Try this solution Enum.GetName Method <asp:TemplateField HeaderText="Category"> <ItemTemplate> <div> <%#… May 16, 2026 at 2:21 pm
  • Editorial Team
    Editorial Team added an answer what version of the wrapper are you running? in 3.4.0… May 16, 2026 at 2:21 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.