Fmdpa Posted July 26, 2010 Share Posted July 26, 2010 How can I block certain pages from being accessed freely by users? For example, I have a page containing variables that are set with the parameters of my mysql_connect() function. I don't want this page to be accessible by anyone but me, since it contains the password for MySQL. If I surround the statement with <?php ?> tags, it will not be viewable in a browser. But when I include the file in another page, I have <?php tags inside another set of <?php tags. If I make the page a .txt file, it will include just fine, but then it is not invisible. How can I make the file containing this classified info so it can be include-ed in other php files, yet it is also invisible to nosy viewers? Link to comment Share on other sites More sharing options...
wirehopper Posted July 26, 2010 Share Posted July 26, 2010 Always use the .php extension for .php files.include will handle the <?php ?> tags fine, it will interpret the code and execute it if appropriate.You can also use a define, like so:init.php<?php define ('INIT_OK',true); ?>index.php<?phpinclude 'init.php';include 'db.php';/* Remainder of index.php ... */db.php<?php if (!defined('INIT_OK')) exit();/* database access credentials */ Link to comment Share on other sites More sharing options...
Fmdpa Posted July 26, 2010 Author Share Posted July 26, 2010 Thanks wirehopper! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.