Jump to content


\n in text database

  • Please log in to reply
2 replies to this topic

#1 Casalen

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 09 September 2006 - 06:45 AM

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.

$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');

#2 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 September 2006 - 07:04 AM

dosent a \n line need a \n\
Wish i new all about php DAM i will have to learn

#3 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 September 2006 - 10:46 AM

The problem is you are using single quotes when writring to calendar.php:
fwrite($new_calendar_file, '<?PHP die("You cannot access this file."); ?>\n');

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:
fwrite($new_calendar_file, "<?PHP die(\"You cannot access this file.\"); ?>\n");

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users