Php file writing
jrwr00 last edited by
ARG! this code is a WTF,
$base64url = $GET["urlaccess"];
$base64 = strtr($base64url, '-', '+/');
$base64txt = base64_decode($base64);
$plaintext = $base64txt;
$filename = 'access.txt';
$somecontent = $plaintext;
FYI:i added those echo's for debugging...... so at lest the script would output something...
it decodes the base64 well, just the only error i get is
Warning: fwrite(): supplied argument is not a valid stream resource in /path/to/logging.php on line 13
djork last edited by
Read the error message. The supplied argument (which would be $handle) is not a valid stream resource. fopen() conveniently returns a stream resource, which would be ideally assigned to a variable called $handle if you wanted to make this work.
Tweenk last edited by
$handle = fopen($filename, 'a+');
Anyway You'd want to add some code like:
if(!$handle) die("Failed to open the file");
course, I don't mean add THIS code, because causing a script to die()
is immoral and evil, and should be used only for debugging or if
something REALLY screws up. Just implement something to report an error
if fopen fails.)
There are also redundant variable assignments, ie. you can use $base64txt instead of $plaintext and $somecontent (this will also make this snippet more readable).