Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PHP to print out a downloadable text file
    primarykey
    data
    text
    <p>My script puts together a set of htaccess rules based on information passed into it and gives the user a downloadable text file with the rules printed out inside. The idea is that an administrator fills out some form information, clicks a downloadable link, gets a text file with the rules printed out inside, opens the file, copies the rules and pastes them into the htaccess file of their domain.</p> <p>I've managed to put together the script that produces these rules. However, the text file seems to ignore all newline characters that I print to it. The tabs work, but the newlines do not. It must have something to do with the encoding I'm using with the header() function calls, but I'm not sure what I'm doing wrong. No amount of Googling as seemed to point me in the right direction. Any input would be appreciated.</p> <p>Here's the code:</p> <pre><code>header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="htaccess.txt"'); header('Content-Transfer-Encoding: binary'); $id = addslashes( $_GET['id']); $location = addslashes( $_GET['location'] ); $location = substr($location, strpos($location, '/', 9 ) + 1 ) . ( ( substr( $location, strlen($location) - 1 ) == '/' ) ? '' : '/' ); $regEx = '([0-9a-zA-Z-_]*)'; $lines = array(); for( $x = 0; $x &lt; 10; $x++ ) { $line = 'RewriteRule ^' . $location; for( $y = 1; $y &lt;= $x; $y++ ) $line .= $regEx . '/'; $line .= '*$' . "\t\t\t\t\t"; $line .= "http://localhost/redirect.php?ring=$id"; $line .= ( $x &gt;= 1 ) ? '&amp;link=$1' : ''; $line .= ( $x &gt; 1 ) ? '&amp;tag' . ( $x - 1 ) . '=$' . $x . ' [NC]' . "\n" : "\n"; $lines[] = $line; } foreach( $lines as $line ) echo $line; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload