PHP newbie with one simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php.newbie
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 3:28 am

PHP newbie with one simple question

Post 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.
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Where's the simple question?

I have idea's but I can't say them because this is in the wrong forum.
php.newbie
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 3:28 am

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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>
php.newbie
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 3:28 am

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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).
php.newbie
Forum Newbie
Posts: 16
Joined: Wed Sep 20, 2006 3:28 am

Post by php.newbie »

Thanks so much aaronhall. Appreciated it.

Richard
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post 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?
Post Reply