Jump to content

\n in text database


Casalen

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]


Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.