On Thu, Mar 15, 2012 at 8:41 PM, Larry <lrrrgg@xxxxxxxxx> wrote: > On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote: >> On Thu, Mar 15, 2012 at 7:51 PM, Larry <lrrrgg@xxxxxxxxx> wrote: >>> On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote: >>>> On Thu, Mar 15, 2012 at 4:59 PM, Larry <lrrrgg@xxxxxxxxx> wrote: >>>>> On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown >>>>> <daniel.brown@xxxxxxxxxxxx> wrote: >>>>>> On Thu, Mar 15, 2012 at 11:30, Larry <lrrrgg@xxxxxxxxx> wrote: >>>>>>> Hello, when I pass a variable whose value originally came from $_GET >>>>>>> or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty >>>>>>> string. Note that the file is successfully opened and written to by >>>>>>> the script, but the variable that originally came from $_GET does not >>>>>>> have its value interpolated in the text file, even though it does get >>>>>>> interpolated in the echo(). >>>>>>> >>>>>>> ---- Code ---- >>>>>>> <? >>>>>>> $meh = $_GET["q"]; >>>>>>> $writeline = ":" . $meh . ":" . strlen($meh) . PHP_EOL; >>>>>>> echo ( $writeline ); >>>>>>> >>>>>>> $fp = fopen("/tmp/wtf.log","w+"); >>>>>>> fwrite($fp, $writeline ); >>>>>>> fclose($fp); >>>>>>> >>>>>>> var_dump($writeline); >>>>>>> ?> >>>>>> >>>>>> Are you sure it's not a permissions-based issue, perhaps when >>>>>> writing as the normal user, then the user as which the web server >>>>>> runs, et cetera? What happens if you completely remove /tmp/wtf.log >>>>>> and re-run your script with the appended query string? >>>>> >>>>> I have removed the wtf.log file between runs, just did it once more. >>>>> Same thing happens. A new file is created, and the contents are "::0" >>>>> >>>>> So I'm sure its not a permissions issue ( However I'm also sure that >>>>> this shouldn't be happening so... ) Thanks. >>>> >>>> The code is working fine here, of course, it should. Is it really >>>> because of the $_GET?, have you tried setting $q = "meh123";? >>>> Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead. >>>> >>>> - Matijn >>> >>> Yes I have tried to set a variable explicitly with a string, and that >>> variable does end up interpolated into the file. I just tried using >>> file_put_contents with the same result. >>> >>> Here is a modified version, showing another variable that does work, >>> and file_put_contents(): >>> >>> <? >>> $meh = $_GET["q"]; >>> $good = "Yay I go in the File" . PHP_EOL; >>> $writeline = ":" . $meh . ":" . strlen($meh) . ":" . $good; >>> echo ( $writeline ); >>> file_put_contents("/tmp/wtf.log", $writeline ); >>> var_dump($writeline); >>> ?> >>> >>> Here the response/stdout: >>> :meh123:6:Yay I go in the File string(31) ":meh123:6:Yay I go in the File " >>> >>> But the file is the same: >>> root@prime:/tmp# rm wtf.log >>> root@prime:/tmp# ls wtf.log >>> ls: cannot access wtf.log: No such file or directory >>> [ I make the request ] >>> root@prime:/tmp# cat wtf.log >>> ::0:Yay I go in the File >> >> Have you checked apache log files for any warnings/errors? >> How about writing $_GET['q'] directly? eg. >> file_put_contents('/tmp/wtf.log', $_GET['q']);? > > Yes I tried using $_GET['q'] directly to no avail. However, you found > a clue! apache error.log is giving this: > PHP Notice: Undefined index: q in /var/www/test/search.php on line 2 > > Strange b/c I am obtaining and using that value successfully in echo()! Well.. That seems pretty buggy, I guess it's a bug in PHP. Try changing q in something else, and maybe you want to submit a bug report to PHP? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php