Page 1 of 1

PHP newbie with one simple question

Posted: Mon Sep 25, 2006 11:11 pm
by php.newbie
Dear All,

I am starting to develop a web application. I am not sure whether I can do this.

I am thinking to have something like this:

I need an include file (or whatever similar if available) to be able to accept paramater like color, bgcolor, etc. and when I call this include file, it will print html tags with the paramters that i pass in.

e.g echo "<table border=$my_parameter1 bgcolor=$my_parameter2>"

By doing this way, I can easily made amendment to my color, size, font type of all my screen whithout having to change all of them.

Any idea how can I implement this using PHP?

Your input is grately appreciated.

Thanks in advance,

Richard
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.

Posted: Tue Sep 26, 2006 1:49 am
by christian_phpbeginner
Hi there,

Do you mean something like this ? Save it as Layout.class.php.

Code: Select all

<?php
   class Layout {
   	   
   	   /**
   	    * Function to display table
   	    *
   	    * @param String $border
   	    * @param String $bgColor
   	    */
      
   	   function displayTable ($border, $bgColor) {
   	      
   	   	   echo "<table border = "$border" bgcolor = "$bgColor">";
   	   	   echo "</table>";
   	   	   
   	   }
   }
?>
Then, in your HTML or other PHP files that use this class:

Code: Select all

<?php
   include ("Layout.class.php");
  
   $myLayout = new Layout();
   $myLayout->displayTable("1", "#FFFFFF");   
?>
php.newbie wrote: By doing this way, I can easily made amendment to my color, size, font type of all my screen whithout having to change all of them.
If this is only your purpose, I suggest to use CSS (Cascading Style Sheets). With CSS you can also change the font color, and have control of your layout in one place, which is your CSS file.

Anyway, you should have asked this in PHP Code forum, I think.

Posted: Tue Sep 26, 2006 2:16 am
by daedalus__
Where's the simple question?

I have idea's but I can't say them because this is in the wrong forum.

Posted: Wed Sep 27, 2006 1:16 am
by php.newbie
Hi All,

Thanks for your reply. and sorry if I posted it in wrong forum.

christian_phpbeginner, yes! that is what i wanted. thanks for the info.

I need to change the size and font based on database value. so, I think CSS may not be able to achieve that. I might be wrong.

Thanks,
Richard

Posted: Wed Sep 27, 2006 3:10 am
by aaronhall
Very simple. Included files inherit the scope that exists at whatever point they are included.... meaning that you can set those variables before you include the file, and the included file will have have access to those same variables. Here's an example:

Code: Select all

<?
$bgColor = "#000000";
$pageTitle = "This is my page title";

include("myIncludeFile.php");

?>
myIncludeFile.php:

Code: Select all

<html>
<head>
<title><?= $pageTitle ?></title>
</head>
<body bgcolor="<?= $bgColor ?>">
...
...
</body>
</html>

Posted: Wed Sep 27, 2006 4:41 pm
by php.newbie
Hi Aaronhall,

Thanks for your reply. appreciated it.

One more question.

How can I keep my include files secure. Let's say I have an include file connectdb.php.

I do not want anyone to know my user and password to connect my database. How did you guys handle the security part?

Thanks,

Richard

Posted: Wed Sep 27, 2006 11:44 pm
by aaronhall
Just as long as the file is being parsed by PHP, none of the file's contents will be displayed. Don't rename your connection include to something like "myConnect.inc" unless apache is set up to interpret .inc files as PHP scripts. If you don't want the include files individually accessed by the user, place them in a non-public directory on your server and include them from there (i.e., don't place them anywhere in your /public_html or /www folder).

Posted: Thu Sep 28, 2006 7:40 am
by php.newbie
Thanks so much aaronhall. Appreciated it.

Richard

Posted: Thu Sep 28, 2006 8:15 am
by kaszu
If i put my config.php file in "public_folder/private/" and create .htaccess file in "private" folder (i'm using Apache server)

Code: Select all

Deny From All
Is this secure? If not, how can i make it secure?