base64_encode an eval(); - php

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';")));

Related

eval() function in PHP, how to make this work properly on the website?

I have a problem with eval() function. Please do not comment something like "Don't use eval" or anything of this kind of thing, as this is not helpful. I have a very good reason to use eval().
Basically I am getting a value from a text field in html on my web page as input code to be executed, like so:
$code = $_POST['code'];
Then, am passing that value to eval function in the html body, like so:
eval($code);
the results are displayed like this:
<h1>test</h1>
the above is displayed string. I want this to execute the html part of it is well. Funny thing is if I try this in a different file like this:
<?php
$code = "echo '<h1><b>TEST</b></h1>';";
eval($code);
?>
I get the desired result, which is a proper processed html element h1 with "TEST" in it.
Any ideas?
Thanks in advance
$_POST['code'] apparently contains HTML entity codes, e.g.
"echo '<h1>test</h1&gt';"
You need to decode it before calling eval.
eval(html_entity_decode($_POST['code']));

how to remove backslashes in json URL with php

i need to remove () backslash in my string when using echo json_encode()?
my example..
$song_url = 116e9155e0afc11555cf33dc9c9bd25d.mp3
$resmsg[] = array("Song_name"=>"$song_name","Song_URL"=>"http://www.kbmusique.com/songs/$song_url");
echo json_encode($resmsg);
my output is
[{"Song_name":"djigh araouioui","Song_URL":"http:\/\/www.kbmusique.com\/songs\/116e9155e0afc11555cf33dc9c9bd25d.mp3"}]
but i need as
[{"Song_name":"djigh araouioui","Song_URL":"http://www.kbmusique.com/songs/116e9155e0afc11555cf33dc9c9bd25d.mp3"}]
Is there a way to solve this? Thank you.
Your comment indicates that you just need to get a copy/pastable URL for testing.
Just parse the JSON and extract the piece of data you need from it. i.e. If you want a text representation of something, then convert the JSON to text, don't try to hack the JSON into a specific form.
You could do this in PHP with json_decode, in a browser with JSON.parse(), or just use a tool such as the Chrome JSONView extension.

Get variables from base64_encode url?

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.

Sending HTML Code Through JSON

I've got a php script which generates HTML content. Is there a way to send back that HTML content through JSON to my webpage from the php script?
Yes, you can use json_encode to take your HTML string and escape it as necessary to be valid JSON (it'll also do things that are unnecessary, sadly, unless you use flags to prevent it). For instance, if your original string is:
<p class="special">content</p>
...json_encode will produce this:
"<p class=\"special\">content<\/p>"
You'll notice it has an unnecessary backslash before the / near the end. You can use the JSON_UNESCAPED_SLASHES flag to prevent the unnecessary backslashes. json_encode(theString, JSON_UNESCAPED_SLASHES); produces:
"<p class=\"special\">content</p>"
Do Like this
1st put all your HTML content to array, then do json_encode
$html_content="<p>hello this is sample text";
$json_array=array(
'content'=>50,
'html_content'=>$html_content
);
echo json_encode($json_array);
All string data must be UTF-8 encoded.
$out = array(
'render' => utf8_encode($renderOutput),
'text' => utf8_encode($textOutput)
);
$out = json_encode($out);
die($out);
In PHP:
$data = "<html>....";
exit(json_encode($data));
Then you should use AJAX to retrieve the data and do what you want with it. I suggest using JQuery: http://api.jquery.com/jQuery.getJSON/
You can send it as a String, why not. But you are probably missusing JSON here a bit since as far as I understand the point is to send just the data needed and wrap them into HTML on the client.
Just to expand on #T.J. Crowder's answer.
json_encode does well with simple html strings, in my experience however json_encode often becomes confused by, (or it becomes quite difficult to properly escape) longer complex nested html mixed with php. Two options to consider if you are in this position are: encoding/decoding the markup first with something like [base64_encode][1]/ decode (quite a bit of a performance hit), or (and perhaps preferably) be more selective in what you are passing via json, and generate the necessary markup on the client side instead.
All these answers didn't work for me.
But this one did:
json_encode($array, JSON_HEX_QUOT | JSON_HEX_TAG);
Thanks to this answer.

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