Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

Passing base64-encoded data in php

I have a page that receive via GET a base64 encoded data, it print data in an input hidden and it pass via get to another page.

The problem is this: when i pass

"Peuq/0X4XhFV+XNa8T06qFrP8lRadORUQBGJ1w6D4m33Jaqx/skKDEJIxjldBrcklboL/uB4C65cjz3BHMPmd3moEJ4GTK5k5Jwf9Ny4BA467bwgeaHJuOS+CjwFlIOzrhSWHTMVl4zWVvwMauuFAjhuMjOOj0/X5L12IcwGTTqLgHo"

via GET it becomes

"Peuq/0X4XhFV XNa8T06qFrP8lRadORUQBGJ1w6D4m33Jaqx/skKDEJIxjldBrcklboL/uB4C65cjz3BHMPmd3moEJ4GTK5k5Jwf9Ny4BA467bwgeaHJuOS CjwFlIOzrhSWHTMVl4zWVvwMauuFAjhuMjOOj0/X5L12IcwGTTqLgHo"

...so openssl can't work. How can I solve it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Base64 can output + signs which are interpreted as spaces when sent in the URL. You can use urlencode to mitigate this:

<?php
$base64_data = $_GET['base64'];
$url_data = urlencode($base64_data);
$field_data = htmlspecialchars($url_data);
printf('<input type="hidden" value="%s" name="pass-it-on">', $field_data);
?>

On page two:

<?php
$base64_data = $_GET['pass-it-on'];
$real_data = base64_decode($base64_data);
?>

Note that there's no need to decode the htmlspecialchars ur urlencode calls since this is done automatically.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...