aaaaaa123456789 icon

PHP quine

aaaaaa123456789 | PRO | 09/27/13 08:04:03 AM UTC | 0 ⭐ | 555 👁️ | Never ⏰ | []
PHP |

1.31 KB

|

None

|

0 👍

/

0 👎

<?php
 
$code = <<<'code_end'
  /*
     This function outputs all of the code used to write this program.
     It effectively makes this program a quine.
  */
  
  // declare $code (remember it contains the code of this function itself)
  global $code;
 
  // take care of the initial opening statements
  $initial = "<?php\n\n\$code = <<<'code_end'\n";
  
  // add the final few lines into an array, which we'll concatenate later
  $lines = array(
    'code_end;',
    '$printing_function = create_function("", $code);',
    '$printing_function();'
  );
  
  // create a variable containing the closing tag
  // the tag is created via concatenation to prevent it from ending the code
  $closing_tag = '?' . '>';
  
  // concatenate the $lines array
  $final_lines = "";
  foreach ($lines as $line)
    $final_lines .= $line . "\n\n";
  
  // send a header to the browser, to show this as text instead of HTML
  header("Content-Type: text/plain");
  
  // concatenate all the individual parts of the code and output it
  $sourcecode = $initial .
                $code . "\n" . // nowdoc syntax doesn't add the final newline
                $final_lines . 
                $closing_tag;
  echo($sourcecode);
    
code_end;
 
$printing_function = create_function("", $code);
 
$printing_function();
 
?>

Comments