Get variables from base64_encode url? - php

I'm studying a way of encoding or encrypting my url variables, but I don't see how to get them back...
Having this
_link_=Home&nc=1&plw=950&pmw=0&prw=
I used to do $_GET['_link_']
but when base64_encode the url like
base64_encode("_link_=Home&nc=1&plw=950&pmw=0&prw=");
echo base64_decode($string);
how do I get my _link_ or my nc variables back?
Thanks

Use http://php.net/manual/en/function.parse-str.php after base64 decode

If you have something like http://www.example.com/?BASE64ENCODEDSTRINGHERE, you can do the following:
$query_string = base64_decode($_SERVER['QUERY_STRING']);
parse_str($query_string, $getdata);
In this case you will have same data in $getdata array as you would normally have in $_GET.

Related

Encode a url into base64 and then decode it

I encode a url having GET parameters using base64 and then decode it back to get the same url back. The string I receive is.
task_type=all&keyword=asdfsd&location=Vasant Kunj&category=17&subcategory=19&price[]=&price[]=100&price[]=300&price[]=500&price[]=above&educations[]=&educations[]=22&educations[]=29&industry[]=&industry[]=1&industry[]=7&experience=6&freshness=1
Now how can I get the original $_GET array back so that I can use it. Or any other way of getting all the parameters so that I can use them. Or any other better way to encode and decode so that original url is not visible to the user.
All help appreciated. Thanx in advance.
As you are encoding the url having GET parameters using base64 you will not be able to get exact GET parameters. But after decoding it you are getting the query string back as you have mentioned, So in this case you can use parse_str(), see doc
Example:
$queryString = "task_type=all&keyword=asdfsd&location=Vasant Kunj&category=17&subcategory=19&price[]=&price[]=100&price[]=300&price[]=500&price[]=above&educations[]=&educations[]=22&educations[]=29&industry[]=&industry[]=1&industry[]=7&experience=6&freshness=1";
parse_str($queryString, $getParamsArray);
var_dump($getParamsArray);
I guess this is what you were looking for...

decode json format data sent via url

consider the following url
index.php?json={uid:guest|10001441}
I am not able to decode the data .
I need the output as {"uid":"guest|10001441"}.
The code i m using is
if (isset($_GET['json']))
{
$url_data = $_GET['json'];
$decoded_data = json_decode($url_data,true);
var_dump($decoded_data);
}
But it gives me output as NULL. What am i doing wrong?? Do i need to pass data in a different format??
It seems impossible to decode a JSON string without double quotes, as it's hard to determine whether a JSON string "{A:B:C}" is encoded from {"A":"B:C"} or from {"A:B":"C"}
You can use urlencode() to encode the JSON string or just ignore the extreme cases and add the double quotes manually to make the JSON string valid, hope this help :D
The data you're passing is not valid JSON. It doesn't have double quotes around it currently. Try this:
if (isset($_GET['json']))
{
$url_data = '"'.$_GET['json'].'"';
$decoded_data = json_decode($url_data,true);
var_dump($decoded_data);
}
Output:
string(20) "{uid:guest|10001441}"
Also, I'd suggest using POST instead of GET here.
If you pass it like this it will work: ?json={"uid":"guest|10001441"}
But I am not sure whether it is a proper method.
The JSON you have in your URL is not valid. PHP's json_decode looks for double quotes around the uid and it's value.
EDIT: Rather than storing the data in the URL as json could you not store the data as key value pairs such as
?uid=value
And then you could do something like
$data = json_encode( $_GET );
you can encode url parameter with base64_encode()
$json=base64_encode('{"uid":"guest|10001441"}');
url will look like this
index.php?json=eyJ1aWQiOiJndWVzdHwxMDAwMTQ0MSJ9
then do like this :-
if (isset($_GET['json']))
{
$url_data = base64_decode($_GET['json']);
$decoded_data = json_decode($url_data,true);
var_dump($decoded_data);
}

Is it possible to base64 encode the file at a URI?

I've just been fiddling around with PHP, and I want to know if it's possible to do such a thing.
If so, can you please provide example code?
Update: What I mean, is I want to encode whatever file may be at the URI, not the URI itself. Sorry if I'm not clear.
You can put:
base64_encode(file_get_contents('http://www.google.com'));
I don't see why not...
<?php $file = file_get_contents("http://example.com/myfile.txt");
$encoded = base64_encode($file);
file_get_contents function will grab the HTML of given URL and base64_encode function will encode it.
<?php
$content = file_get_contents("http://google.com");
$encodedContent = base64_encode($content);
?>
You want to base64-encode a URL? Simple...
base64_encode($uri)

base64_encode an eval();

Is threre a way to encode something like this :
eval("echo 'String';");
with base64_encode, and then to call base64_decode and get the result String without any echo or additional eval functions?
You are asking for base64_decode to execute arbitrary code? That doesn't work. It operates on data, not code, and so whatever you decode has to be a data string. Can't you just encode 'String' directly? Otherwise, you'll have to run eval again to turn data into code: eval(base64_decode($mysterydata));.
eval('die(base64_decode("bla"))');
something like this?
if you want to obfuscate your code have a look at this site:
http://demo.dmwtechnologies.com/PHP/PhpObfuscator/index.php
Not with echo in the eval, but how about this?:
echo base64_decode(base64_encode(eval("return 'String';")));

convert this to japanese character (encoding)

Please help me convert this... I dont know how to call this kind of data, is it hex?
2%E6%9C%8819%E6%97%A5
I believe that this should be printed as 2月19日
How can I convert 2%E6%9C%8819%E6%97%A5 to be 2月19日 using PHP?
Thank You
That looks like it's URL encoded http://en.wikipedia.org/wiki/Url_encoding
PHP UrlDecode might do the trick.
http://www.php.net/manual/en/function.urldecode.php
There's an example at that link which shows url decoding the querystring of a page. I don't know PHP, but you might want soemthing like the following:
<?php
$original = "2%E6%9C%8819%E6%97%A5";
$decoded = urldecode($original);
echo $decoded;
?>

Categories