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-ID: 322359

Url: https://administrator.de/forum/how-to-write-phpinfo-with-special-character-to-file-322359.html

Ausgedruckt am: 18.04.2025 um 18:04 Uhr

131381
131381 29.11.2016 aktualisiert um 12:16:07 Uhr
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
thankusomuch
thankusomuch 29.11.2016 um 12:22:38 Uhr
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
131381
131381 29.11.2016 aktualisiert um 12:30:32 Uhr
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!
thankusomuch
thankusomuch 29.11.2016 um 12:36:57 Uhr
Goto Top
iam reading face-smile
thankusomuch
thankusomuch 29.11.2016 um 12:43:52 Uhr
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?
131381
131381 29.11.2016 aktualisiert um 12:58:32 Uhr
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.
thankusomuch
thankusomuch 29.11.2016 aktualisiert um 13:06:49 Uhr
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?
131381
131381 29.11.2016 aktualisiert um 13:23:38 Uhr
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
thankusomuch
thankusomuch 29.11.2016 um 13:23:39 Uhr
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!!!
131381
131381 29.11.2016 aktualisiert um 13:30:34 Uhr
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
thankusomuch
thankusomuch 29.11.2016 um 13:33:15 Uhr
Goto Top
no worries
thanks anyway