note 101670 added to function.require

From: Date: Mon, 03 Jan 2011 20:30:00 +0000
Subject: note 101670 added to function.require
Groups: php.notes 
Request: Send a blank email to php-notes+get-175428@lists.php.net to get a copy of this message
Require is a really neat function, compared to include. You can use it for security purposes. For example, consider that you have a database that's based on simple text-files. Theoretically, someone could type in the URL of those text-files, and view them directly in their browser. This is as opposed to what you want: those files only to be viewable through your own PHP script. Otherwise, the data won't be properly formatted, or much worse, you won't be able to do a proper secure authorization or authentication. So, here's the trick. Rename your .txt files to .php files. The first line should be this... require('this_file_does_not_exist_and_will_never_exist'); Then, after that first line, the rest of the file is your database information. If someone tries access the file directly, they'll get an error, and see no information (danged hackers!). But, your PHP script that displays the database file will know that this line is there. This is assuming that you reprogram your text-database, php-front-end to ignore the first line of files when reading data. It's not encryption, but it's powerful security, quick and cheap, for custom-built databases. ---- Server IP: 69.147.83.197 Probable Submitter: 68.0.209.235 ---- Manual Page -- http://www.php.net/manual/en/function.require.php Edit -- https://master.php.net/note/edit/101670 Del: integrated -- https://master.php.net/note/delete/101670/integrated Del: useless -- https://master.php.net/note/delete/101670/useless Del: bad code -- https://master.php.net/note/delete/101670/bad+code Del: spam -- https://master.php.net/note/delete/101670/spam Del: non-english -- https://master.php.net/note/delete/101670/non-english Del: in docs -- https://master.php.net/note/delete/101670/in+docs Del: other reasons-- https://master.php.net/note/delete/101670 Reject -- https://master.php.net/note/reject/101670 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175428) next »