Jump to content

Archived

This topic is now archived and is closed to further replies.

Casalen

\n in text database

Recommended Posts

Okay, so I'm expanding the user data functions on a script. It now creates a directory for each new user, including a few files. Each of the database files starts with a die command so that it can't be easily read from the browser. After the die command is written the character \n, which should translate into a new line in the text file. So I take a file, open it in notepad++ to see if the data wrote, and find the data written... except that I see \n instead of a new line. All except for one file, base.db.php, which works perfectly. Any suggestions? I don't really need that part, but it's frustrating anyway. I'm pretty tired right now, so forgive me if it's something I should have seen.

[code]$new_index_file = fopen("$userdir" . "/index.php", "a");
$new_base_file = fopen("$userdir" . "/base.db.php", "a");
$new_profile_file = fopen("$userdir" . "/profile.db.php", "a");
fwrite($new_base_file, "<?PHP die(\"You cannot access this file.\"); ?>|\n");
fwrite($new_base_file, "$add_time|$reglevel|$regusername|$regpassword|$regnickname|$regemail|$regusergroups|0|0||||\n");
fwrite($new_profile_file, "<?PHP die(\"You cannot access this file.\"); ?>|\n");
fwrite($new_profile_file, "$firstname|$lastname|$birthday|$hidemail|$title|$description|$status|0|0|||\n");
$new_calendar_file = fopen("$userdir" . "/calendar.db.php", "a");
fwrite($new_calendar_file, '<?PHP die("You cannot access this file."); ?>\n');[/code]


Share this post


Link to post
Share on other sites
The problem is you are using single quotes when writring to calendar.php:
[code=php:0]fwrite($new_calendar_file, '<?PHP die("You cannot access this file."); ?>\n');[/code]

If you use single quotes. PHP will treat \n as-s (meaning normal text). it will not treat \n as a new line character. The solution is to use double quotes:
[code=php:0]fwrite($new_calendar_file, "<?PHP die(\"You cannot access this file.\"); ?>\n");[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.