thankusomuch
Goto Top

How to write phpinfo with special character to file

hi, hope u guys can help me face-smile

http://192.168.2.101/write.php?info=test&abcd

my write.php file:
<?php
$newUrl = html_entity_decode($_GET["info"]);  
file_put_contents("log.txt", $newUrl. "\r\n", FILE_APPEND | LOCK_EX);  

?>


RESULT = test
but it should be = test&abcd

how can i do that?

thanks

Content-Key: 322359

Url: https://administrator.de/contentid/322359

Printed on: April 18, 2024 at 18:04 o'clock

Mitglied: 131381
131381 Nov 29, 2016 updated at 11:16:07 (UTC)
Goto Top
Use urlencode() and urldecode() instead for encoding strings which are used as parameters, or use POST instead of GET.

Seien Sie vorsichtig beim Umgang mit Variablen, die HTML-Entities enthalten könnten. Angaben wie &amp, &copy und &pound werden vom Browser geparst und die eigentliche Entität wird anstelle des gewünschten Variablennamens verwendet. Dies ist eine naheliegende Schwierigkeit, über die das W3C bereits seit Jahren informiert. Die entsprechende Referenz finden Sie hier: » http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2. 
http://php.net/manual/de/function.urlencode.php

Regards
Member: thankusomuch
thankusomuch Nov 29, 2016 at 11:22:38 (UTC)
Goto Top
thanks u so much for helping

but didnt work face-sad

file_put_contents("log.txt", urldecode($_GET["info"]). "\r\n", FILE_APPEND | LOCK_EX);  

same Result face-sad

regards
Mitglied: 131381
131381 Nov 29, 2016 updated at 11:30:32 (UTC)
Goto Top
Zitat von @thankusomuch:

thanks u so much for helping

but didnt work face-sad

> file_put_contents("log.txt", urlencode($_GET["info"]). "\r\n", FILE_APPEND | LOCK_EX);  
> 
Wrong!!
You have to first encode the string for the url parameter
So the URL needs to look like
http://192.168.2.101/write.php?info=test%26abcd
in urlencoded form, and in the php script you then use urldecode($_GET["info"]) to decode the parameter!

PLEASE READ THE DOCUMENTATION FIRST, THANKS!
Member: thankusomuch
thankusomuch Nov 29, 2016 at 11:36:57 (UTC)
Goto Top
iam reading face-smile
Member: thankusomuch
thankusomuch Nov 29, 2016 at 11:43:52 (UTC)
Goto Top
working with php since 2 days face-smile not that easy.
but did i understand u right?
the url in the browser can be "http://192.168.2.101/write.php?info=test&amp;abcd"
but my php script needs to encode it to "http://192.168.2.101/write.php?info=test%26abcd"
and then i can use it.

or does it have to be "http://192.168.2.101/write.php?info=test%26abcd" in the browser?
and i have to change the url before i send it?

right?
Mitglied: 131381
131381 Nov 29, 2016 updated at 11:58:32 (UTC)
Goto Top
and i have to change the url before i send it?
Yes, that's the key. You do this with urlencode, how i described above.
Member: thankusomuch
thankusomuch Nov 29, 2016 updated at 12:06:49 (UTC)
Goto Top
ok thats strange because in the full phpinfo page it shows up correctly?

so why can i not just grab the full line from there , convert it and extract it to the logfile. possible?
Mitglied: 131381
131381 Nov 29, 2016 updated at 12:23:38 (UTC)
Goto Top
Zitat von @thankusomuch:

ok thats strange because in the full phpinfo page it shows up correctly?
so why can i not just grab the full line from there , convert it and extract it to the logfile. possible?
??????? You are writing in crosswords face-sad

http://www.jonasjohn.de/snippets/php/phpinfo2file.htm
Member: thankusomuch
thankusomuch Nov 29, 2016 at 12:23:39 (UTC)
Goto Top
face-sad
i mean if i write:

PHPInfo('test.log');  
function PHPInfo($target_file){
ob_start();
phpinfo();
$info = ob_get_contents();
ob_end_clean();
$fp = fopen($target_file, "w+");  
fwrite($fp, $info);
fclose($fp);
}
in my write.php file

and enter url: http://192.168.2.101/write.php?info=test&amp;abcd

then i get
on LINE 954:
<tr><td class="e">_SERVER["QUERY_STRING"]</td><td class="v">info=test&amp;amp;abcd</td></tr>  
so why can i not just grab all between info= and </td></tr>
so only: test&amp;amp;abcd

Which i can then conver back to: test?abcd

??
thanks anyway
u helped me out a lot!!!
Mitglied: 131381
131381 Nov 29, 2016 updated at 12:30:34 (UTC)
Goto Top
You need to rename your function because ist overwrites the original phpinfo() function.

You are still writing in crosswords... im out now in this crackbrained beginner session .. face-sad
Member: thankusomuch
thankusomuch Nov 29, 2016 at 12:33:15 (UTC)
Goto Top
no worries
thanks anyway