Detect base64 encoding in PHP?

后端 未结 12 1899
鱼传尺愫
鱼传尺愫 2020-12-05 02:10

Is there some way to detect if a string has been base64_encoded() in PHP?

We\'re converting some storage from plain text to base64 and part of it lives in a cookie

12条回答
  •  遥遥无期
    2020-12-05 02:55

    Here's my solution:

    if(empty(htmlspecialchars(base64_decode($string, true)))) { return false; }

    It will return false if the decoded $string is invalid, for example: "node", "123", " ", etc.

提交回复
热议问题