php define tag

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
ade234uk
Forum Newbie
Posts: 2
Joined: Sat Mar 04, 2006 5:45 am

php define tag

Post by ade234uk »

I can see the advantages of using the php define tag for example I could specify all my form fields on one page and link this to another .php page using an include tag and using the echo tag where I want the form field to be displayed for example. What I wanted to know is if this is the correct way to use the define tag.

<?php
// define.php
define("form_field_first_name", "<input type=text name=first_name size=20>");
define("form_field_last_name", "<input type=text name=last_name size=20>");
?>


<?
// show_form.php
include "define.php";

echo form_field_first_name; //
echo form_field_last_name; //
?>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I don't think it's the intended way, but you can certainly do that if it's feasible in your application.

I think define() was intended to declare (aka. define) variables that you will never want to change throughout your whole app.

For example, I use define like this:

config.php

Code: Select all

<?php
  define("USERNAME", "Jay");
  define("PASSWORD", "xxx");
?>
index.php

Code: Select all

<?php
  include('config.php');
  //Let the user login here
?>
Post Reply