SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot boballoo's Avatar
    Join Date
    Dec 2001
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to shorten long confirmation URLS

    When people register at my site they receive a confirmation email with a very long URL in it. This URL is often broken by their email app or does not work for various reasons. It would help to shorten these URLs. Can this be done using Mod Rewrite? This seems to be backwards to me since the URLs are in the email messages but maybe I can have the URLs shortened automatically and inserted into the email. I just read my first article on this an hour ago so please make your replies simple if possible. I am not a programmer but the programmer I use says this is not possible. I disagree but I need ammunition.
    EditFast
    Any Document --> Any Time!
    Web Site Copy Editing & Proofreading


  2. #2
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm don't know much about url rewriting but i would say that this would not seem possible because of the fact that the user is going to need to click the link that gives corresponds to the input you will need to check against your database to make sure that the information is valid.

    However, you could shorten the url in other ways, it would just mean that you would have to change your implementation of how the confirmation url gets validated.. instead of spitting out the whole md5, or base64 or whatever hashing/encoding algorithem used to spit out the url, you could alter it in some way and then do the same on the end that recieves the url..
    for instance you could make it really simple and chop them in half...or take every other letter.. this could add a bit of complexity into the queries though.. but it depends...


    I dont think this is your problem, but you could also simply say
    click <a href="www.yourdomain.com/confirm.php?uname=somereallylongbsthatnobodycanunderstnad&amp;pw=anotherbunchofmumbojumbo>Here</a>
    to confirm your account.. i'm assuming you knew that though

    then offer a plaintext version as well in case they do not recieve html mail

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    boballoo,

    Of course it's possible!

    However, mwolfe is also correct in stating that you need to shorten your URL (if possible). Your post failed to provide a sample which would have shown the types of info you are trying to have sent.

    On the assumption that you're using PHP/MySQL, consider saving the needed information in your database and assigning a computer-generated (random) password which could be used as the unique key (rather than id=#) for some small measure of security. The remainder of the information you need then does not have to be contained in the URL.

    BTW, if your programmer is that clueless, go find someone who actually knows how to program.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Zealot boballoo's Avatar
    Join Date
    Dec 2001
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    This is the type of thing we are dealing with. I thought it could be shortened using Mod Rewrite in the .htaccess file but now that I think about it that is not possible since it has to contain the key info to confirm the user. I know we can shorten the URL by using short forms of the words such as this: action=a and/or confirm&email=c and so on but it still leaves us with something like this:
    Code:
    
    
    I don't want to use HTML mail in any of the automatic functions of the web site. Too many errors. Too many messages rejected. Too many complaints from people saying they can't read it etc. I always use plain text only for mailings to my users.

    Originally my goal was to learn a little about Mod Rewrite so I could remove the ton of redirects I have in my .htaccess file after moving some directories around. But I got sidetracked with this thought about being able to use it to change the URL in the email. This is what my programmer said was impossible. I am beginning to agree with him.
    EditFast
    Any Document --> Any Time!
    Web Site Copy Editing & Proofreading


  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    boballoo,

    http://www.mydomain.com/confirm_acco...709f1a1f17e619

    Your URL contains repetitive information:
    confirm_account.php and action=confirm
    email=user@somedomain.com is likely already stored in your db
    code=1f66e27c0b067dbd95709f1a1f17e619 is likely also stored in your db

    Both email and code are likely to be unique in the db (especially the code).

    With that in mind, your link should be http://www.mydomain.com/confirm/1f66...709f1a1f17e619 which, by mod_rewrite, would be converted simply by using:
    Code:
    RewriteEngine On
    RewriteRule ^confirm/([a-z0-9]{32})$ confirm_account.php/action=confirm&code=$1 [L]
    I'd like to think that you don't really need confirm in the URL so, if you DO need the email (isn't that already in your db?), then http://www.mydomain.com/1f66e27c0b06...somedomain.com would be processed by:
    Code:
    RewriteEngine On
    RewriteRule ^([a-z0-9]{32})/([A-Za-z0-9\.\_]+@[a-z0-9\-]*(\.[a-z]{2,8}){1,2})$ confirm_account.php/action=confirm&email=$2code=$1 [L]
    Sorry for that second atom - standard format validation for e-mail address
    NOTE: I've assumed, by your example, that code will always be a 32 character string of lowercase and digits, ergo, ([a-z0-9]{32}).

    If you want to learn about mod_rewrite, have a read of the article at datakoncepts.com/seo as it takes you from setting up Apache, testing that it works, building good regex, mod_rewrite's flags and provides a warning (and solution) for the problems generated with relative links. Yeah, it's tough to remember that your objective was to drain the swamp with all those alligators nipping at your backside.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Zealot boballoo's Avatar
    Join Date
    Dec 2001
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! That's a lot more than this alligator can chew at one time...but thank you for the quick lesson on how little I know. I will take this all in tomorrow and start once again with a fresh mind. Thank you for your help.
    EditFast
    Any Document --> Any Time!
    Web Site Copy Editing & Proofreading


  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    boballoo,

    Hey! That's what these forums are all about - helping each other learn! In other words, you're quite welcome!

    That article is a work in progress and has just been updated with the "when should you" and "flags" sections. It's actually a very basic treatment as there's so much more that can be done with mod_rewrite - stick around this forum and read the threads 'cause people have some very interesting questions and problems!

    Learn all you can - then pass the favor along to others.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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