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.
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.
Here's the 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 < 10; $x++ ) {
$line = 'RewriteRule ^' . $location;
for( $y = 1; $y <= $x; $y++ )
$line .= $regEx . '/';
$line .= '*$' . "\t\t\t\t\t";
$line .= "http://localhost/redirect.php?ring=$id";
$line .= ( $x >= 1 ) ? '&link=$1' : '';
$line .= ( $x > 1 ) ? '&tag' . ( $x - 1 ) . '=$' . $x . ' [NC]' . "\n" : "\n";
$lines[] = $line;
}
foreach( $lines as $line )
echo $line;