Url safe base64 encoding and decoding in PHP

Whenever passing base64 encoded strings in url should always urlencode or do the following which replaces characters that should not be in a query string value with safe characters so query string will not be malformed. When you use the encode method must also use the decode method to convert those characters back to the original.


       /**
         * Custom base64 encoding. Replace unsafe url chars
         *
         * @param string $val
         * @return string
         */
        static function base64_url_encode($val) {

            return strtr(base64_encode($val), '+/=', '-_,');

        }

        /**
         * Custom base64 decode. Replace custom url safe values with normal
         * base64 characters before decoding.
         *
         * @param string $val
         * @return string
         */
        static function base64_url_decode($val) {

            return base64_decode(strtr($val, '-_,', '+/='));

        }

Leave a comment

20 Comments.

  1. Excellent site you have got here.. It’s difficult to
    find excellent writing like yours nowadays.
    I truly appreciate individuals like you! Take care!!

  2. It is often the case that the limitations of your current situation will
    point the way towards the ideal solution for the future.
    ) And if leather jeans aren’t your thing search for
    the new “covered” pants that have the look of leather yet are
    less demanding to wear. Tycho Brahe was well-known in his
    lifetime as an astronomer and alchemist.

  3. Trying to find out if there make money online is room for you.
    There are thousands of people jump on this twenty first century it
    can be able to write or ramble on about matters using unrelated information to your niche and
    tell them why they earn. If you are in luck because you won’t
    make any sense nor would it be promotional
    websites or in some social networking came along this
    was much more opportunities to make money online.

  4. you’re in reality a excellent webmaster. The website loading velocity is incredible.
    It seems that you’re doing any distinctive trick.
    Furthermore, The contents are masterwork. you’ve performed a wonderful task
    on this matter!

  5. Spot on with this write-up, I absolutely believe that this
    site needs much more attention. I’ll probably be back
    again to see more, thanks for the info!

  6. You’re so interesting! I do not think I have read something like this before.
    So nice to discover someone with a feew genuine thoughts on this topic.
    Seriously.. many thanks for starting this up.
    Thhis site is something that is required on the web, someone
    with some originality!

  7. It has clear massaging gel and it works very well with open toe shoes.
    The magnetic fields in the earth organize the human body
    to completely a wonderful extent. When insurance companies stress
    preventive health, they always emphasize doctor exams over laboratory tests.

  8. Valuable info. Lucky me I discovered your web site accidentally, and I am surprised
    why this coincidence did not happened in advance!
    I bookmarked it.

  9. Ⲩou mɑde a numbeг of nice points there. I did a search
    on the issue and foսnd mainly folks will consent with your blоg.

  10. Aᴡ,this was an incredibly nice post. Spendіng some time and actual effort
    to make a top notch article… bbut what сan I say… I put things off a whole lot
    and never manage to get nearly anythinng ɗone.

  11. Bởi tính thân thiện và an toàn mà số đông phụ nữ lựa chọn nâng
    mũi bằng sụn tự thân.
    Bởi vì sao nâng mũi bằng sụn tự thân lại an toàn với
    cơ thể?
    Để nâng mũi cần những loại sụn tự thân nào?

    Nâng mũi bằng sụn tự thân lấy chất liệu sụn từ chính cơ thể bạn để làm phẫu thuật.

    Do vậy nên sụn sẽ tương thích với cơ thể,
    dễ dàng hợp nhất thành một khối thống nhất,
    và có độ bền gần như vĩnh viễn.
    Đặc biệt là bạn sẽ có chiếc mũi đẹp hài hòa với
    gương mặt.

  12. My brother recоmmended І may like this blog. He was once entirely right.
    This post truly made my day. Yоu can not imagine
    simрly how a lօt timе I had spᥱntt for this info!
    Thanks!

  13. Hello would you mind sharing which blog platform you’re using?
    I’m planning to sart my own blogg soon but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your design seems different then mot blogs and I’m looking foor something
    completely unique. P.S Sorry for being off-topic but I
    had tto ask!

  14. It’s remarkable in favor of me to have a web page, which is helpful for my knowledge.
    thanks admin

  15. I am regular visitor, how are you everybody? This paragraph posted at
    this website is genuinely good.

  16. Having read this I thought it was very enlightening.
    I appreciate you taking the time and energy to put this article together.
    I once again find myself spending way too much time both reading and leaving comments.
    But so what, it was still worth it!

  17. You’re so interesting! I don’t suppose I have read through anything
    like this before. So great to discover someone with a few genuine thoughts on this
    subject matter. Really.. thank you for starting this up.
    This web site is something that is required on the web, someone with
    a bit of originality!

  18. It’ѕ amazing tto pay a quick visit this website аnd reading thе views of all
    maes rgarding thіs piece of writing, while I am alѕo zealoous
    ᧐f gettіng experience.

Trackbacks and Pingbacks: