Page 1 of 1

php define tag

Posted: Sat Mar 04, 2006 7:01 am
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; //
?>

Posted: Sat Mar 04, 2006 8:04 am
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
?>