Created
April 28, 2012 16:32
-
-
Save wakhub/2520108 to your computer and use it in GitHub Desktop.
PHP and Perl and Python/Ruby polyglot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#<?php eval('echo "PHP Code\n";'); __halt_compiler(); ?> | |
print ((("b" + "0" == 0) and eval('"Perl Code\n"')) or (0 and "Ruby Code\n" or "Python Code")); | |
__DATA__ = 1 | |
""""" | |
__END__ | |
===== This is comment of all. ===== | |
outputs: | |
$ perl polyglot.pl.php.py.rb | |
Perl Code | |
$ php polyglot.pl.php.py.rb | |
#PHP Code | |
$ python polyglot.pl.php.py.rb | |
Python Code | |
$ ruby polyglot.pl.php.py.rb | |
Ruby Code | |
$ | |
""" |
you can run php with the output_buffering parameter enabled php --define output_buffering=On $file
.
then in the first line fo your polyglot you can use ob_end_clean()
to drop everything that was printed before and __halt_compiler()
to not even read the rest, thus yielding a "real" PHP
on stdout, without magic/invis characters. e.g.:
#define X[<?php ob_end_clean();echo"PHP\n";__halt_compiler();#print(("ALGOL68",newline))COMMENT]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the
eval(...)
in the PHP section doesn't do anything, it can be compressed and the hash can be removed.#<?php echo "\x08PHP Code\n";__halt_compiler();?>