Monday, 15 September 2014

processing php tags inside a file/variable -



processing php tags inside a file/variable -

i have lots of files may or not have php tags (<?php... ?>) within it.

first off, need check if php tags exist in files. no problem here. utilize fopen, save content variable, , strpos this.

next, if has php tags, save temporary file , utilize ob_start() include, , ob_get_clean() save output variable farther processing.

is there alternative doing method? perhaps more simpler one, not having save temporary file instead process variable?

another alternative have in mind utilize fopen , strpos check if tags nowadays in file , utilize ob_start(), include (the original file), , ob_get_clean() save output variable farther processing.

any comments?

i appreciate response and/or comments.

btw, in case might ask, working on backend accepts input users may or may not include php tags.

you question doesn't mention you're doing, i'm assuming you're doing incredibly unsafe "parse out code in <?php ?> blocks can run". short answer: don't this.

okay guess that's not answer, more of statement. here's why: if users trusted users , they're in personal circle of friends , they're experts, need 1 slipup screw entire system. accidental unlink()? bad, you're screwed. , no, "we don't have worry that, everyone's cool" not retort. someone, @ point, going screw up, , longer takes, more stand lose =)

with said, depends want do. if want run in place, save input temp file, include() file, , unlink() again. entire thing execute in scope, , have been treated if normal php file on system.

warning this incredibly dangerous, never on non-sandboxed, public server, if it's on intranet. approach literally total anonymous remote access solution warning

if want strip out code , non-code deal them separately, if have nil each other, simple non-greedy preg_match_all find code blocks, doing str_replace kill them off in original submitted content give array of code blocks, , input string blocks removed. job done (although i'm not sure why wouldn't utilize separate submission processes content , code in case, since they'll independent of each other).

php tags backend

No comments:

Post a Comment