我的手机显示信审失败 是什么意思

php&base64_encode&在url编码上应用(转载)
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,看好是编码,并不是加密。
编码过程不解释了,Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 =
24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。
php 用base64_encode() 编码的数据要比原始数据多占用 33% 左右的空间。
格式是大小写字母、数字、“=”号、“+”号和“/”号
但“=”等号最多只有两个
正则匹配就是 【 [a-zA-Z0-9=+/]+ 】
所以看到有大小写字母的字符串并且有一个或两个等号结束的。基本可以判断是base64编码
base64不适合直接放在URL里传输,发现base64编码中有“/”
“=”符号。为解决此问题,可采用一种用于URL的改进Base64编码,它不在末尾填充'='号,并将标准Base64中的“+”和“/”分别改成了
“_”和“-”,这样就免去了在URL编解码和数据库存储时所要作的转换。
找在找去,找到一个php函数:
转自:/?post=282
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。&& && &&&& && &&其它登录: &&
您的位置:>
& php base64_decode — 对MIME base64编码数据进行解码
php base64_decode — 对MIME base64编码数据进行解码
时间: 18:39:16 & 编辑:一切随缘 & 文章来源:php教程网 已阅读:1025 次
广告投放:
WEB开发网:
&&& &&& php base64_decode & 对MIME
base64编码数据进行解码
&&& &&& 说明
&&& &&& string base64_decode
( string $encoded_data )
&&& &&& base64_decode() 对 encoded_data
进行解码,返回原始数据,失败则返回 FALSE。返回的数据可能是二进制的。
&&& &&& Example#1
base64_decode() 示例
&&& &&& &?php
&&& &&& $str =
'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
&&& &&& echo
base64_decode($str);
&&& &&& ?&
此示例将显示:
&&& &&& This is an encoded string
&&& &&& 参见 base64_encode() 和 ? RFC 2045 的 6.8 章节。
--------------------------------------------------------------------------------
&&& URLsbase64_encodeURLs
&&& &&& PHP Manual
&&& &&& User contributed
&&& &&& Tom
&&& &&& This function
supports &base64url& as described in Section 5 of RFC 4648, &Base 64 Encoding
with URL and Filename Safe Alphabet&
&&& &&& &&& &?php
&&& &&& &&&
function base64url_decode($base64url)
&&& &&& &&& {
&&& &&& &&& &&&
$base64 = strtr($base64url, '-_', '+/');
&&& &&& &&& &&& $plainText =
base64_decode($base64);
&&& &&& &&& &&& return ($plainText);
&&& &&& &&&
&&& &&& &&& ?&
&&& &&& Starson
&&& To expand on Jes' post:
&&& &&& The change took place between 5.0.5
and 5.1.0.& Exactly where I don't know or care.
&&& &&& In short php
&= 5.0.5's base64_decode( $string ) will assume that a space is meant to be a
+ sign where php &= 5.1.0's base64_decode( $string ) will no longer make that
assumption.& I did not see this noted in the change log.
&&& &&& Please
note that, as of this writing, mb_convert_encoding( $string, &UTF-8&, &BASE64& )
still behaves as base64_decode( $string ) did in php &= 5.0.5 regardless of
the version of php you are running.
&&& &&& Jes
&&& &&& I've come across an interesting issue with an external program that
submits a gzcompressed base64_encoded string to PHP via POST. The external
program encodes the string using the occasional & & (space) character, however
if I encode the same original string within PHP (using base64_encode), it uses a
&+& (plus) character wherever the external program would use a space. On my
deployed machine, running PHP 4.3.9, base64_decode is fine with the & & (space)
characters, but my test server running 5.1.4 is not. It took me a while to
figure out that was the issue, but I ended up fixing it with a
&&& &&& &?php
&&& &&& $post_data = str_replace(&
&,&+&,$_POST['string'])
&&& &&& ?&
&&& &&& This fix works on
both the 4.3.9 and 5.1.4 machines. I am sure that the external program is
probably not conforming to the standard, and it isn't a PHP problem per- but
incase anybody else ever runs into that.
&&& &&& gabor dot barta at freemail
&&& &&& Hi,
&&& &&& I just would
like to add a comment, i was strugging with it for some time. So i opened a POP3
mailbox fopen, and listed the emails with attachments. I copied the base64
encoded text to a file and saved it. Then i tried to decode this file to a jpeg
picture, and it just didnt work... Then i realized that there were some spaces
in the text file....
&&& &&& Hope it will help anyone.
&&& &&& paul at ijsfontein dot nl
&&& The user notes posted here helped me a lot in writing the PHP code to upload
uuencoded files to a server using $_POST. Hardest thing to figure out was why
the files came out scrambled and corrupted. After comparing the original file
with the file reconstructed by the uudecode script, I found out that a simple
&stripcslashes& on the posted data will do the trick.
&&& &&& So, to
upload any kind of uuencoded file using a POST:
&&& &&& 1. send the raw file
data to the PHP script
&&& &&& 2. $uuencoded_data =
stripcslashes($_POST['filedata']);
&&& &&& 3. strip the marker lines from
$uuencoded_data (first line, last line and second last line of the data. Each
line is seperated by a LF (chr(10)) character.)
&&& &&& 4. $decoded_data =
uudecode($stripped_uuencoded_data); (this function can be found in the user
notes here).
&&& &&& 5. Use the script provided in one of the user notes on
this page to write the decoded data to a binary file.
&&& &&& That should
do the trick!
&&& &&& tobias at silverxnet dot de
&&& &&& I was wondering how to decode attached images within mails.
Basically they are mostly JPEG files, so it was obviously to write a function
that decodes JPEG images.
&&& &&& I guess the plainest way to do so was the
following:
&&& &&& &?php
&&& &&& function base64_to_jpeg(
$inputfile, $outputfile ) {
&&& &&& & /* read data (binary) */
$ifp = fopen( $inputfile, &rb& );
&&& &&& & $imageData = fread( $ifp,
filesize( $inputfile ) );
&&& &&& & fclose( $ifp );
&&& &&& & /* encode
& write data (binary) */
&&& &&& & $ifp = fopen( $outputfile, &wb& );
&&& &&& & fwrite( $ifp, base64_decode( $imageData ) );
&&& &&& & fclose(
&&& &&& & /* return output filename */
&&& &&& & return(
$outputfile );
&&& &&& ?&
&&& &&& This function
decodes the given inputfile (a filename!) and saves it to the given outputfile
(a filename as well) and then returns the output filename for further usage
(e.g. redirect, imagejpeg() and so on).
&&& &&& I thought that might be
&&& &&& dharwood at synopsistechnologies dot com
&&& &&& Encode/DEcode PAGE.
&&& &&& Here is a page
that will accept plain text password and return an encoded password.& It will
also do the opposite.& It will allow you to enter an encoded password and
generate the plain text password... (just in case you forgot your
password.)
&&& &&& &?php
&&& &&& if
(isset($_POST['text_pass'])){
&&& &&& &&& $but=$_POST['button'];
&&& process_form();
&&& &&& }else{
&&& &&& &&& print_form();
&&& &&& function process_form(){
&&& &&& & switch
($_POST['button']){
&&& &&& &&& case &Get Encoded&:
&&& &&& &&& &&&
$text_pass = $_REQUEST['text_pass'];
&&& &&& &&& &&& echo
&&html&\n&;
&&& &&& &&& &&& echo &&head&\n&;
&&& &&& &&& &&&
echo &&title&Password Encoding&/title&\n&;
&&& &&& &&& &&& echo
&&meta http-equiv=\&Content-Type\& content=\&text/
charset=iso-8859-1\&&\n&;
&&& &&& &&& &&& echo &&/head&\n&;
&&& &&& &&& echo &&body&\n&;
&&& &&& &&& &&& echo &&table
border=\&0\& cellspacing=\&0\& cellpadding=\&4\& width=\&100%\&&\n&;
&&& &&& &&& echo &&div align=\&center\&&\n&;
&&& &&& &&& &&& echo
&&h3 align=center&Password Encoding Page&/h3&\n&;
&&& &&& &&& &&&
echo &&table align=\&center\& border=\&0\&&\n&;
&&& &&& &&& &&& echo
&&& &&& &&& &&& echo &&td &&b&You Entered:&
&/b&&/td&\n&;
&&& &&& &&& &&& echo
&&td&$text_pass&/td&\n&;
&&& &&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& &&& $test =
base64_encode(serialize($text_pass));
&&& &&& &&& &&& echo
&&& &&& &&& &&& echo &&td &&b&Your encoded
password (base 64) is:& &/b&&/td&\n&;
&&& &&& &&& &&& echo
&&td&$test&/td&\n&;
&&& &&& &&& &&& echo &&/tr&\n&;
&&& &&& &&& $untest = unserialize(base64_decode($test));
&&& &&& &&& &&& echo
&&& &&& &&& &&& echo &&td &&b&To double test,
your UNencoded password (base 64) is:& &/b&&/td&\n&;
&&& &&& &&&
&&& echo &&td&$untest&/td&\n&;
&&& &&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& &&& echo &&/table&\n&;
&&& &&& &&& &&&
&&& &&& &&& case &Get UNEncoded&:
&&& &&& &&& &&& $text_pass =
$_REQUEST['text_pass'];
&&& &&& &&& &&& echo &&html&\n&;
&&& &&& &&&
&&& echo &&head&\n&;
&&& &&& &&& &&& echo &&title&Password
Encoding&/title&\n&;
&&& &&& &&& &&& echo &&meta
http-equiv=\&Content-Type\& content=\&text/
charset=iso-8859-1\&&\n&;
&&& &&& &&& &&& echo &&/head&\n&;
&&& &&& &&& echo &&body&\n&;
&&& &&& &&& &&& echo &&table
border=\&0\& cellspacing=\&0\& cellpadding=\&4\& width=\&100%\&&\n&;
&&& &&& &&& echo &&div align=\&center\&&\n&;
&&& &&& &&& &&& echo
&&h3 align=center&Password Encoding Page&/h3&\n&;
&&& &&& &&&
&&& &&& &&& &&& echo &&table align=\&center\& border=\&0\&&\n&;
&&& &&& &&& echo &&tr&\n&;
&&& &&& &&& &&& echo &&td
&&b&You Entered:& &/b&&/td&\n&;
&&& &&& &&& &&& echo
&&td&$text_pass&/td&\n&;
&&& &&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& &&& $untest =
unserialize(base64_decode($text_pass));
&&& &&& &&& &&& echo
&&& &&& &&& &&& echo &&td &&b&Your UNencoded
password (base 64) is:& &/b&&/td&\n&;
&&& &&& &&& &&& echo
&&td&$untest&/td&\n&;
&&& &&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& &&& echo &&/table&\n&;
&&& &&& &&&
&&& &&& &&& default:
&&& &&& &&&
&&& &&& &&& &&&
&&& &&& function print_form(){
&&& &&& &&& echo
&&html&\n&;
&&& &&& &&& echo &&head&\n&;
&&& &&& &&& echo
&&title&Password Encoding&/title&\n&;
&&& &&& &&& echo &&meta
http-equiv=\&Content-Type\& content=\&text/
charset=iso-8859-1\&&\n&;
&&& &&& &&& echo &&/head&\n&;
&&& echo &&body&\n&;
&&& &&& &&& echo &&table border=\&0\&
cellspacing=\&0\& width=\&100%\&&\n&;
&&& &&& &&& echo &&div
align=\&center\&&\n&;
&&& &&& &&& echo &&h3 align=center&Password
Encoding Page&/h3&\n&;
&&& &&& &&& echo &&tr&\n&;
&&& &&& &&&
echo &&form action=\&$_SERVER[PHP_SELF]\& method=\&post\&&\n&;
&&& echo &&table align=\&center\& border=\&0\&&\n&;
&&& &&& &&& echo
&&& &&& &&& echo &&td align=\&right\&&&b&Password
to Encode/Decode:&/b&&/td&\n&;
&&& &&& &&& echo &&td
align=\&right\&&&;
&&& &&& &&& echo && &input type=\&text\&
name=\&text_pass\& size=\&30\& &\n&;
&&& &&& &&& echo
&&/td&\n&;
&&& &&& &&& echo &&/tr&\n&;
&&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& echo &&tr&\n&;
&&& &&& &&& echo
&&& &&& &&& echo &&\n&;
&&& &&& &&& echo
&&/tr&\n&;
&&& &&& &&& echo &&td &&;
&&& &&& &&& echo
&&input type=\&submit\& name=\&button\& value=\&Get
Encoded\&&&br&\n&;
&&& &&& &&& echo &&/td&&;
&&& &&& &&&
echo &&td &&;
&&& &&& &&& echo &&input type=\&submit\&
name=\&button\& value=\&Get UNEncoded\&&&br&\n&;
&&& &&& &&& echo
&&& &&& &&& echo &&/tr&\n&;
&&& &&& &&& echo
&&/table&\n&;
&&& &&& &&& echo &&/form&\n&;
&&& &&& &&& echo
&&& &&& &&& echo &&/table&\n&;
&&& &&& &&& echo
&&/body&\n&;
&&& &&& &&& echo &&/html&\n&;
&&& &&& dhirendrak at yahoo dot com
&&& &&& Heading : Your customizable encode&
&&& &&& and decode function.
&&& &&& A customizable encoded and decode
&&& &&& Function which can
encode and decode
&&& &&& the data. You need to pass variable to&
&&& the encode function to encrypt and&
&&& &&& whenever you want you can
&&& &&& data by using decode function.
&&& &&& Cracking /
hacking of encoded value
&&& &&& is impossible, until user know the&
&&& actual coding.&
&&& &&& &?php
&&& &&& function encoded($ses)&
&&& &&& {&&&&
&&& &&& & $sesencoded = $
&&& &&& & $num =
mt_rand(3,9);
&&& &&& & for($i=1;$i&=$$i++)&
&&& &&& & {
&&& &&& &$sesencoded =&
&&& &&& &&& &base64_encode($sesencoded);
&&& &&& & $alpha_array =&
&&& &&& & array('Y','D','U','R','P',
&&& &&& & 'S','B','M','A','T','H');
&&& &&& & $sesencoded =&
& $sesencoded.&+&.$alpha_array[$num];
&&& &&& & $sesencoded =
base64_encode($sesencoded);
&&& &&& & return $
&&& &&& }//end
of encoded function
&&& &&& function decoded($str)
&&& && $alpha_array =&
&&& &&& && array('Y','D','U','R','P',&
&&& &&& &&
'S','B','M','A','T','H');
&&& &&& && $decoded =&
&&& &&& &&&
base64_decode($str);
&&& &&& && list($decoded,$letter) =&
&&& &&& &&
split(&\+&,$decoded);
&&& &&& && for($i=0;$i&count($alpha_array);$i++)
&&& &&& && {
&&& &&& && if($alpha_array[$i] == $letter)
&&& &&& &&
&&& &&& && }
&&& &&& && for($j=1;$j&=$i;$j++)&
&&& &&& &&
&&& &&& &&& & $decoded =&
&&& &&& &&& && base64_decode($decoded);
&&& &&& && }
&&& &&& && return $
&&& &&& }//end of decoded
&&& &&& ?&
&&& &&& http://members.lycos.co.uk/dhirendrak
&&& &&& Klaus Fehrenbacher
&&& &&& this
script can correct the bug
&&& &&& &?php
&&& &&& $enc =
chunk_split(preg_replace('! 5 2| 5| 2!','',$enc));
&&& &&& $enc =
base64_decode($enc);
&&& &&& ?&
&&& &&& nsayer at kfu dot com
&&& &&& I used to do uudecode as a C module, but I've
discovered a really fast way to do it in PHP. Here it is:
&&& &&& function uudecode($encode) {
$b64chars=&ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz+/&;
&&& &&& & $encode =
preg_replace(&/^./m&,&&,$encode);
&&& &&& & $encode =
preg_replace(&/\n/m&,&&,$encode);
&&& &&& & for($i=0; $i&strlen($encode);
&&& &&& &&& if ($encode[$i] == '`')
&&& &&& &&& & $encode[$i] =
&&& &&& &&& $encode[$i] = $b64chars[ord($encode[$i])-32];
&&& &&& & while(strlen($encode) % 4)
&&& &&& &&& $encode .= &=&;
&&& &&& & return base64_decode($encode);
&&& &&& ?&
&&& &&& This is the PHP equivalent to perl's unpack(&u&,___). That is,
you need to strip the 'begin' and 'end' lines from the typical uuencoded file.
上一篇:下一篇:
本文地址:/content/article/php-xuexi/16850.html(转载请保留)
相关关键词搜索:php,base64_decode,MIME,base64,编码,数据,进行,解码
你可能喜欢
php sprintf与printf函数用法区别,下面是一个示例:四舍五入保留小数点后两位...
php ereg_replace将其替换replacement@替换的匹配项则会返回原字符串,string ereg_replace ( string $pattern , str...
php计算e的指数@php exp用法示例, float exp ( float $arg ), 返回 e 的 arg 次方值。
Note: 用 \'e\' 作为自然对数的底 2...
php判断文件或目录是否存在@php file_exists函数教程, bool file_exists ( string $filename ),如果由 filename 指定的...
* 以上用户言论只代表其个人观点,不代表网站的观点或立场
纯JS代码小游戏
热门关键词
(已有826人阅读本文)
(已有911人阅读本文)
(已有654人阅读本文)
(已有1752人阅读本文)
(已有1640人阅读本文)
(已有682人阅读本文)
(已有2292人阅读本文)
(已有960人阅读本文)
(已有1499人阅读本文)
WEB技术QQ交流群: 站长Q号:
版权所有者:WEB开发网 地址:云南省文山州砚山县盘龙乡
滇ICP备号-1
特别声明:本站内容仅供参考,不作为设计及确切依据!想了解更多,可立即进入本文讲的是php Base64编码文件二进制流主要使用,
Base64编码文件二进制流是使用base64_encode函数对文件二进制信息进行编码。
base64_encode — 使用 MIME base64 对数据进行编码
Report a bug 说明
Base64编码文件二进制流是使用base64_encode函数对文件二进制信息进行编码。
base64_encode — 使用 MIME base64 对数据进行编码
Report a bug 说明
string base64_encode ( string $data )
使用 base64 对 data 进行编码。
设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。
Base64-encoded 数据要比原始数据多占用 33% 左右的空间。
具体方式为:
$path = 'image.jpg';
$fp = fopen($path, 'rb');
// 以二进制形式打开文件
$content = fread($fp, filesize($path)); // 读取文件内容
fclose($fp);
$content = base64_encode($content); // 将二进制信息编码成字符串
上述程序输出的结果类似:R0lGODlhEAAQAJECAISEhAAAhP///wAAACH5BAEAAAIALAAAAAAQABAAAAImlI
+pyxedQADQhVflpfAK30jG1lwmqIgWl6CClmKHxn6mdVb6zhcAOw==
这样我们成功将一个文件转换成了字符串。
解码过程非常简单,使用base64_decode($content)即可。
上述处理过程主要用途有:
1、接口传输
主要适用于通过WEB接口将文件从一个站点向另一个站点传输,可以用于XML信息。
2、存入数据库
当然,将图片等文件信息保存到数据库中完全可以不用这么做,但这种方式依然适用。对于数据库新手来说这种方式更可接受。因为这完全是一个字符串。
3、文件加密
文件加密可大家用得比较少,举个例子,假如我们有一套PHP程序需要保护,必须有授权码的用户才能正常运行,那么我们可能使用授权码来对文件进行加密,即将上述编码后的字符串再次加工。运行过程需要授权码才可运行。
当然还有其它用途,根据各人的需要灵活使用。
以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索字符串
二进制base64编码、js二进制转base64编码、二进制转base64编码、js 二进制 base64编码、二进制文件base64编码,以便于您获取更多的相关知识。
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效率,降低 IT 成本...
RDS是一种稳定可靠、可弹性伸缩的在线数据库服务。支持MySQL、SQL Server、PostgreSQL、高...
云栖社区()为您免费提供相关信息,包括
的信息,还有二进制base64编码、js二进制转base64编码、二进制转base64编码、js 二进制 base64编码、二进制文件base64编码等
,所有相关内容均不代表云栖社区的意见!查看: 2349|回复: 1
[课堂笔记]
注册时间最后登录阅读权限150积分5583精华3帖子
本帖最后由 燕十八 于
21:06 编辑
原文地址:&&转载请注明此地址.
按:的课堂上,有位同学问这样一个问题:
“我在用 base64_encode 对用户名进行编码时,会出来等号,是不是可以去掉?”
跟我来看完这篇文章,答案即揭晓.1: 为什么需要base64?ASCII码一共规定了128个字符的编码,这128个符号,范围在[0,127]之间.
其中,[0,31],及127, 33个属于不可打印的控制字符.在电子邮件传输信息时,有些邮件网关会把[0,31]这些控制字符给悄悄清除.
还有的早期程序,收到[128,255]之间的国际字符时,甚至会发生错误.如何在不同邮件网关之间安全的传输控制字符,国际字符,甚至二进制文件?
于是作为MIME多媒体电子邮件标准的一部分—base64被开发出来.2: 一句话说完base64怎么工作的?把N字节的内容对应的8*N位, 每6位砍成1段,得到 (8*N)/6 个单元,
每个单元的值,都在[0,63]之间,再把其值对应1个ascii字符,拼接起来,OK!base64_encode(’PHP’) ==& ‘UEhQ’, 编码过程如下:3: 如果每6位砍成1段,但不能整除,余下2个位或4位怎么办?用”0″来补至6位, 并再次转化为”base64字符表”中的某个字符.然后,再用”=”字符当做6个位,继续填充,直至总位数能被8带整除.字符串二进制序列(红字为填充位)编码结果PHP100 000UEhQit111 010000 xxxxxxaXQ=bool110 111 0000 xxxxxx xxxxxxYm9vbA==4:base64表示图片通过上面的演示,可以看出,base64也可以编码二进制文件,如邮件中的图片和附件.
编码后,我们可以在网页或邮件的源码里,直接体现此图片,
而不必把图片放在服务器上,引用其链接.用例:base64(’abc.png’) ==& ‘encoded-result’;
则在网页中, &img src=”data:image/base64,encoded-result” /&看到下面这个5角星了吗? 右键看源码,就会发现图片是一串字符串
5: base64编码后字节的变化很容易推算出, 编码后,每6个位变成8个位.
因此,编码后字节约比编码前多33%.6: base64串结尾的”=”可以去掉吗?从上面的编码规则可以反推出, 在base64解码的过程中, 要清除掉结尾处的等号,
然后再反查”base64索引与字母对照表”,转换成原始的字节序列.那么,去掉尾部的等号,并没有丢失原始信息,但结构变得不规范.
解码前是否判断完整性,这取决于你的应用程序.实测PHP中的base64_decode函数,并不检测尾部的等号是否完整.
附件: 你需要才可以下载或查看附件。没有帐号?
注册时间最后登录阅读权限10积分39精华0帖子
新手上路, 积分 39, 距离下一级还需 11 积分
好文章就应该顶起来......
Powered by}

我要回帖

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信